- scheduler: fix FCGI compile

- API: add files for version 6 graphics

api/
    Makefile.am
    graphics2.C (new)
    graphics2_unix.C (new)
    graphics2_win.C (new)
sched/
    Makefile.am

svn path=/trunk/boinc/; revision=12714
This commit is contained in:
David Anderson 2007-05-22 20:12:45 +00:00
parent 043c91e594
commit fe68a746fd
7 changed files with 598 additions and 4 deletions

View File

@ -47,13 +47,24 @@ graphics_impl_files = \
txf_util.C \
x_opengl.C
graphics2_files = \
gutil.C \
gutil_text.C \
reduce_lib.C \
texfont.c \
texture.C \
txf_util.C \
graphics2.C \
graphics2_unix.C
EXTRA_DIST = *.h
if BUILD_GRAPHICS_API
graphics_libs = \
libboinc_graphics_api.a \
libboinc_graphics_lib.a \
libboinc_graphics_impl.a
libboinc_graphics_impl.a \
libboinc_graphics2.a
else
graphics_libs =
endif
@ -70,6 +81,8 @@ libboinc_graphics_lib_a_SOURCES = $(graphics_lib_files)
libboinc_graphics_lib_a_CPPFLAGS = -I$(top_srcdir)/lib
libboinc_graphics_impl_a_SOURCES = $(graphics_impl_files)
libboinc_graphics_impl_a_CPPFLAGS = -I$(top_srcdir)/lib
libboinc_graphics2_a_SOURCES = $(graphics2_files)
libboinc_graphics2_a_CPPFLAGS = -I$(top_srcdir)/lib
## install header-files with prefix-subdir BOINC/ to avoid name-conflicts
includedir = ${prefix}/include/BOINC/

59
api/graphics2.C Normal file
View File

@ -0,0 +1,59 @@
double boinc_max_fps;
double boinc_max_gfx_cpu_frac;
bool throttled_app_render(int x, int y, double t) {
static double total_render_time = 0;
static double time_until_render = 0;
static double last_now = 0;
static double elapsed_time = 0;
double now, t0, t1, diff, frac;
bool ok_to_render = true;
now = dtime();
diff = now - last_now;
last_now = now;
// ignore interval if negative or more than 1 second
//
if ((diff<0) || (diff>1.0)) {
diff = 0;
}
// enforce frames/sec restriction
//
if (boinc_max_fps) {
time_until_render -= diff;
if (time_until_render < 0) {
time_until_render += 1./boinc_max_fps;
} else {
ok_to_render = false;
}
}
// enforce max CPU time restriction
//
if (boinc_max_gfx_cpu_frac) {
elapsed_time += diff;
if (elapsed_time) {
frac = total_render_time/elapsed_time;
if (frac > boinc_max_gfx_cpu_frac) {
ok_to_render = false;
}
}
}
// render if allowed
//
if (ok_to_render) {
if (boinc_max_gfx_cpu_frac) {
boinc_calling_thread_cpu_time(t0);
}
app_graphics_render(x, y, t);
if (boinc_max_gfx_cpu_frac) {
boinc_calling_thread_cpu_time(t1);
total_render_time += t1 - t0;
}
return true;
}
return false;
}

166
api/graphics2_unix.C Normal file
View File

@ -0,0 +1,166 @@
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include "x_opengl.h"
#include "app_ipc.h"
#include "util.h"
#include "graphics_api.h"
#include "boinc_gl.h"
#include "boinc_glut.h"
#define TIMER_INTERVAL_MSEC 30
static int xpos = 100, ypos = 100;
static int win_width = 600, win_height = 400;
static int clicked_button;
static int win=0;
static APP_INIT_DATA aid;
bool fullscreen;
static void get_window_title(APP_INIT_DATA& aid, char* buf, int len) {
if (aid.app_version) {
snprintf(buf, len,
"%s version %.2f [workunit: %s]",
aid.app_name, aid.app_version/100.0, aid.wu_name
);
} else {
snprintf(buf, len,
"%s [workunit: %s]",
aid.app_name, aid.wu_name
);
}
}
static void close_window() {
exit(0);
}
// This callback is invoked when a user presses a key.
//
void keyboardD(unsigned char key, int /*x*/, int /*y*/) {
if (fullscreen) {
close_window();
} else {
boinc_app_key_press((int) key, 0);
}
}
void keyboardU(unsigned char key, int /*x*/, int /*y*/) {
if (fullscreen) {
close_window();
} else {
boinc_app_key_release((int) key, 0);
}
}
void mouse_click(int button, int state, int x, int y){
clicked_button = button;
if (fullscreen) {
close_window();
} else {
if (state) {
boinc_app_mouse_button(x, y, button, false);
} else {
boinc_app_mouse_button(x, y, button, true);
}
}
}
void mouse_click_move(int x, int y){
if (fullscreen) {
close_window();
} else if (clicked_button == 2){
boinc_app_mouse_move(x, y, false, false, true);
} else if (clicked_button == 1){
boinc_app_mouse_move(x, y, false, true, false);
} else if (clicked_button == 0){
boinc_app_mouse_move(x, y, true, false, false);
} else{
boinc_app_mouse_move(x, y, false, false, false);
}
}
static void maybe_render() {
int width, height;
width = glutGet(GLUT_WINDOW_WIDTH);
height = glutGet(GLUT_WINDOW_HEIGHT);
if (throttled_app_render(width, height, dtime())) {
glutSwapBuffers();
#ifdef __APPLE__
MacGLUTFix(fullscreen);
if (need_show) {
glutShowWindow();
need_show = false;
}
#endif
}
}
static void make_window() {
char window_title[256];
get_window_title(aid, window_title, 256);
win = glutCreateWindow(window_title);
glutReshapeFunc(app_graphics_resize);
glutKeyboardFunc(keyboardD);
glutKeyboardUpFunc(keyboardU);
glutMouseFunc(mouse_click);
glutMotionFunc(mouse_click_move);
glutDisplayFunc(maybe_render);
glEnable(GL_DEPTH_TEST);
app_graphics_init();
#ifdef __APPLE__
glutWMCloseFunc(CloseWindow); // Enable the window's close box
BringAppToFront();
// Show window only after a successful call to throttled_app_render();
// this avoids momentary display of old image when screensaver restarts
// which made image appear to "jump."
need_show = true;
#endif
if (fullscreen) {
glutFullScreen();
}
}
static void boinc_glut_init() {
const char* args[2] = {"screensaver", NULL};
int one=1;
win = 0;
glutInit (&one, (char**)args);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(xpos, ypos);
glutInitWindowSize(600, 400);
}
static void timer_handler(int) {
maybe_render();
glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0);
}
void boinc_graphics(int argc, char** argv) {
for (int i=1; i<argc; i++) {
if (!strcmp(argv[i], "--fullscreen")) {
fullscreen = true;
}
}
boinc_get_init_data(aid);
if (!strlen(aid.app_name)) {
strcpy(aid.app_name, "BOINC Application");
}
boinc_glut_init();
make_window();
glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0);
glutMainLoop();
}

343
api/graphics2_win.C Executable file
View File

@ -0,0 +1,343 @@
// Event loop and support functions for Windows versions
// of BOINC applications w/ graphics.
// Platform-independent code should NOT be here.
//
/* This Code Was Created By Jeff Molofee 2000.
* A HUGE thanks to fredric echols for cleaning up
* and optimizing this code, making it more flexible!
* If you've found this code useful, please let me know.
* Visit My Site At nehe.gamedev.net
* Adapted to BOINC by Eric Heien
*/
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
#include "boinc_win.h"
#else
#include "config.h"
#endif
#include "diagnostics.h"
#include "boinc_api.h"
#include "graphics_api.h"
#include "app_ipc.h"
#include "util.h"
#include "graphics_impl.h"
#define BOINC_WINDOW_CLASS_NAME "BOINC_app"
#define WM_SHUTDOWNGFX WM_USER+1
const UINT WM_BOINCSFW = RegisterWindowMessage(TEXT("BOINCSetForegroundWindow"));
static HDC hDC = NULL;
static HGLRC hRC = NULL;
static HWND hWnd = NULL; // Holds Our Window Handle
static HINSTANCE hInstance; // Holds The Instance Of The Application
static RECT rect = {50, 50, 50+640, 50+480};
static int current_graphics_mode = MODE_HIDE_GRAPHICS;
static int acked_graphics_mode = -1;
static POINT mousePos;
static HDC myhDC;
static bool visible = true;
static bool window_ready=false;
static UINT_PTR gfx_timer_id = 0;
void close_window() {
window_ready=false;
wglMakeCurrent(NULL,NULL); // release GL rendering context
if (hRC) {
wglDeleteContext(hRC);
}
if (hWnd && hDC) {
ReleaseDC(hWnd,hDC);
}
if (hWnd) {
DestroyWindow(hWnd);
}
exit(0);
}
void SetupPixelFormat(HDC hDC) {
int nPixelFormat;
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of structure.
1, // always 1.
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGl
PFD_DOUBLEBUFFER, // support double buffering
PFD_TYPE_RGBA, // support RGBA
32, // 32 bit color mode
0, 0, 0, 0, 0, 0, // ignore color bits
0, // no alpha buffer
0, // ignore shift bit
0, // no accumulation buffer
0, 0, 0, 0, // ignore accumulation bits.
16, // number of depth buffer bits.
0, // number of stencil buffer bits.
0, // 0 means no auxiliary buffer
PFD_MAIN_PLANE, // The main drawing plane
0, // this is reserved
0, 0, 0 }; // layer masks ignored.
// this chooses the best pixel format and returns index.
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
// This set pixel format to device context.
SetPixelFormat(hDC, nPixelFormat, &pfd);
}
static void make_window() {
RECT WindowRect = {0,0,0,0};
int width, height;
DWORD dwExStyle;
DWORD dwStyle;
if (fullscreen) {
HDC screenDC=GetDC(NULL);
WindowRect.left = WindowRect.top = 0;
WindowRect.right=GetDeviceCaps(screenDC, HORZRES);
WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES);
ReleaseDC(NULL, screenDC);
dwExStyle=WS_EX_TOPMOST;
dwStyle=WS_POPUP;
while(ShowCursor(false) >= 0);
} else {
WindowRect = rect;
dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
while(ShowCursor(true) < 0);
}
APP_INIT_DATA aid;
boinc_get_init_data(aid);
if (!strlen(aid.app_name)) strcpy(aid.app_name, "BOINC Application");
char window_title[256];
get_window_title(aid, window_title, 256);
hWnd = CreateWindowEx(dwExStyle, BOINC_WINDOW_CLASS_NAME, window_title,
dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top,
WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
NULL, NULL, hInstance, NULL
);
SetForegroundWindow(hWnd);
GetCursorPos(&mousePos);
hDC = GetDC(hWnd);
myhDC=hDC;
SetupPixelFormat(myhDC);
hRC = wglCreateContext(hDC);
if (hRC == 0) {
ReleaseDC(hWnd, hDC);
return;
}
if(!wglMakeCurrent(hDC, hRC)) {
ReleaseDC(hWnd, hDC);
wglDeleteContext(hRC);
return;
}
// use client area for resize when not fullscreen
if (current_graphics_mode != MODE_FULLSCREEN) {
GetClientRect(hWnd, &WindowRect);
}
width = WindowRect.right-WindowRect.left;
height = WindowRect.bottom-WindowRect.top;
ShowWindow(hWnd, SW_SHOW);
SetFocus(hWnd);
app_graphics_init();
app_graphics_resize(width, height);
window_ready=true;
}
void parse_mouse_event(UINT uMsg, int& which, bool& down) {
switch(uMsg) {
case WM_LBUTTONDOWN: which = 0; down = true; break;
case WM_MBUTTONDOWN: which = 1; down = true; break;
case WM_RBUTTONDOWN: which = 2; down = true; break;
case WM_LBUTTONUP: which = 0; down = false; break;
case WM_MBUTTONUP: which = 1; down = false; break;
case WM_RBUTTONUP: which = 2; down = false; break;
}
}
// message handler (includes timer, Windows msgs)
//
LRESULT CALLBACK WndProc(
HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam // Additional Message Information
) {
switch(uMsg) {
case WM_ERASEBKGND: // Check To See If Windows Is Trying To Erase The Background
return 0;
case WM_KEYDOWN:
if(!window_ready) return 0;
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
} else {
boinc_app_key_press((int)wParam, (int)lParam);
}
return 0;
case WM_KEYUP:
if(!window_ready) return 0;
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
} else {
boinc_app_key_release((int)wParam, (int)lParam);
}
return 0;
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
if(!window_ready) return 0;
if (fullscreen) {
close_window();
} else {
int which;
bool down;
POINT cPos;
GetCursorPos(&cPos);
parse_mouse_event(uMsg, which, down);
boinc_app_mouse_button(cPos.x, cPos.y, which, down);
}
return 0;
case WM_MOUSEMOVE:
if(!window_ready) return 0;
POINT cPos;
GetCursorPos(&cPos);
if (fullscreen) {
if(cPos.x != mousePos.x || cPos.y != mousePos.y) {
close_window();
}
} else {
boinc_app_mouse_move(
cPos.x, cPos.y,
(wParam&MK_LBUTTON)!=0,
(wParam&MK_MBUTTON)!=0,
(wParam&MK_RBUTTON)!=0
);
}
return 0;
case WM_CLOSE:
boinc_exit(0);
return 0;
case WM_PAINT:
PAINTSTRUCT ps;
RECT winRect;
HDC pdc;
pdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &winRect);
FillRect(pdc, &winRect, (HBRUSH)GetStockObject(BLACK_BRUSH));
EndPaint(hWnd, &ps);
return 0;
case WM_SIZE:
if ( SIZE_MINIMIZED == wParam ) {
visible = FALSE;
} else {
visible = TRUE;
}
if(!window_ready) return 0;
app_graphics_resize(LOWORD(lParam), HIWORD(lParam));
return 0;
case WM_SHUTDOWNGFX:
close_window();
return 0;
default:
if ( WM_BOINCSFW == uMsg ) {
SetForegroundWindow(hWnd);
}
}
// Pass All Unhandled Messages To DefWindowProc
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
BOOL reg_win_class() {
WNDCLASS wc; // Windows Class Structure
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
// Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = BOINC_WINDOW_CLASS_NAME; // Set The Class Name
// Attempt To Register The Window Class
if (!RegisterClass(&wc)) {
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
return TRUE;
}
BOOL unreg_win_class() {
if (!UnregisterClass(BOINC_WINDOW_CLASS_NAME,hInstance)) {
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL
}
return TRUE;
}
static VOID CALLBACK timer_handler(HWND, UINT, UINT, DWORD) {
RECT rt;
int width, height;
GetClientRect(hWnd, &rt);
width = rt.right-rt.left;
height = rt.bottom-rt.top;
if (throttled_app_render(width, height, dtime())) {
SwapBuffers(hDC);
}
}
void win_graphics_event_loop() {
MSG msg;
reg_win_class();
gfx_timer_id = SetTimer(NULL, 1, 30, (TIMERPROC)&timer_handler);
while (1) {
if (GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
break;
}
}
unreg_win_class();
}
void boinc_graphics(int argc, char** argv) {
for (int i=1; i<argc; i++) {
if (!strcmp(argv[i], "--fullscreen")) {
fullscreen = true;
}
}
boinc_get_init_data(aid);
if (!strlen(aid.app_name)) {
strcpy(aid.app_name, "BOINC Application");
}
make_window(fullscreen);
win_graphics_event_loop();
}

View File

@ -5170,3 +5170,15 @@ Rom 22 May 2007
clientgui/
AdvancedFrame.cpp, .h
David 22 May 2007
- scheduler: fix FCGI compile
- API: add files for version 6 graphics
api/
Makefile.am
graphics2.C (new)
graphics2_unix.C (new)
graphics2_win.C (new)
sched/
Makefile.am

View File

@ -54,9 +54,9 @@ $biomed = array(
array(
"World Community Grid",
"http://www.worldcommunitygrid.org/",
"IBM",
"Biomedicine",
"Advance our knowledge of human disease.",
"IBM Corporate Community Relations",
"Humanitarian research on new and infectious disease, natural disasters and hunger.",
"To further critical non-profit research on some of humanity's most pressing problems by creating the world's largest volunteer computing grid. Research includes HIV/AIDS, cancer, muscular dystrophy, dengue fever, and many more.",
"wcg.jpg",
),
),

View File

@ -174,6 +174,7 @@ fcgi_SOURCES = \
sched_msgs.C \
sched_locality.C \
sched_timezone.C \
edf_sim.C \
../db/boinc_db.C \
../db/db_base.C \
../lib/base64.C \