2002-08-09 21:43:59 +00:00
|
|
|
#include "graphics_api.h"
|
2002-09-17 21:54:59 +00:00
|
|
|
#include "error_numbers.h"
|
2002-08-09 21:43:59 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
|
|
|
|
2002-09-18 22:58:01 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
DWORD WINAPI win_graphics_event_loop( LPVOID duff );
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 21:15:23 +00:00
|
|
|
#ifdef __APPLE_CC__
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#include "mac_app_opengl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern GRAPHICS_INFO gi;
|
|
|
|
|
|
|
|
int boinc_init_opengl() {
|
|
|
|
#ifdef BOINC_APP_GRAPHICS
|
2002-09-18 22:15:49 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD threadId;
|
|
|
|
HANDLE hThread;
|
|
|
|
|
|
|
|
// Create the graphics thread, passing it the graphics info
|
|
|
|
hThread = CreateThread( NULL, 0, win_graphics_event_loop, &gi, CREATE_SUSPENDED, &threadId );
|
|
|
|
|
|
|
|
// Set it to idle priority
|
|
|
|
SetThreadPriority (hThread, THREAD_PRIORITY_HIGHEST);
|
|
|
|
|
|
|
|
// Start the graphics thread
|
|
|
|
ResumeThread( hThread );
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 21:15:23 +00:00
|
|
|
#ifdef __APPLE_CC__
|
|
|
|
OSErr theErr = noErr;
|
|
|
|
ThreadID graphicsThreadID = 0;
|
|
|
|
ThreadEntryUPP entry_proc;
|
|
|
|
|
|
|
|
entry_proc = NewThreadEntryUPP( mac_graphics_event_loop );
|
|
|
|
|
|
|
|
// Create the thread in a suspended state
|
|
|
|
theErr = NewThread ( kCooperativeThread, entry_proc,
|
|
|
|
(void *)(&gi), 0, kNewSuspend, NULL, &graphicsThreadID );
|
|
|
|
if (theErr != noErr) return ERR_THREAD;
|
|
|
|
|
|
|
|
// In theory we could do customized scheduling or install thread disposal routines here
|
|
|
|
|
|
|
|
// Put the graphics event loop into the ready state
|
|
|
|
SetThreadState( graphicsThreadID, kReadyThreadState, kNoThreadID );
|
|
|
|
|
|
|
|
YieldToAnyThread();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_finish_opengl() {
|
2002-09-18 22:15:49 +00:00
|
|
|
return 0;
|
2002-09-18 21:15:23 +00:00
|
|
|
}
|
|
|
|
|
2002-09-17 21:54:59 +00:00
|
|
|
int write_graphics_file(FILE* f, GRAPHICS_INFO* gi) {
|
2002-08-05 00:29:34 +00:00
|
|
|
fprintf(f,
|
2002-09-17 21:54:59 +00:00
|
|
|
"<graphics_info>\n"
|
2002-09-11 21:41:42 +00:00
|
|
|
" <graphics_xsize>%d</graphics_xsize>\n"
|
|
|
|
" <graphics_ysize>%d</graphics_ysize>\n"
|
|
|
|
" <graphics_mode>%d</graphics_mode>\n"
|
|
|
|
" <graphics_refresh_period>%f</graphics_refresh_period>\n"
|
2002-09-17 21:54:59 +00:00
|
|
|
"</graphics_info>\n",
|
|
|
|
gi->xsize,
|
|
|
|
gi->ysize,
|
|
|
|
gi->graphics_mode,
|
|
|
|
gi->refresh_period
|
2002-08-05 00:29:34 +00:00
|
|
|
);
|
2002-09-11 21:41:42 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-08-05 00:29:34 +00:00
|
|
|
}
|
|
|
|
|
2002-09-17 21:54:59 +00:00
|
|
|
int parse_graphics_file(FILE* f, GRAPHICS_INFO* gi) {
|
2002-08-05 00:29:34 +00:00
|
|
|
char buf[256];
|
|
|
|
while (fgets(buf, 256, f)) {
|
2002-09-11 21:41:42 +00:00
|
|
|
if (match_tag(buf, "</graphics_info>")) return 0;
|
2002-09-17 21:54:59 +00:00
|
|
|
else if (parse_int(buf, "<graphics_xsize>", gi->xsize)) continue;
|
|
|
|
else if (parse_int(buf, "<graphics_ysize>", gi->ysize)) continue;
|
|
|
|
else if (parse_int(buf, "<graphics_mode>", gi->graphics_mode)) continue;
|
|
|
|
else if (parse_double(buf, "<graphics_refresh_period>", gi->refresh_period)) continue;
|
2002-08-05 00:29:34 +00:00
|
|
|
else fprintf(stderr, "parse_core_file: unrecognized %s", buf);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|