2012-07-02 18:51:02 +00:00
|
|
|
// DEPRECATED
|
|
|
|
|
2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2005-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-01-20 23:22:22 +00:00
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2009-02-26 00:23:23 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <csetjmp>
|
2004-07-21 22:45:03 +00:00
|
|
|
#include <unistd.h>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <cstring>
|
2009-02-26 00:23:23 +00:00
|
|
|
#include <csignal>
|
2002-11-12 20:59:00 +00:00
|
|
|
#include "x_opengl.h"
|
|
|
|
|
2007-07-31 13:11:26 +00:00
|
|
|
#include "app_ipc.h"
|
2004-07-15 21:54:48 +00:00
|
|
|
#include "util.h"
|
2005-01-08 01:17:51 +00:00
|
|
|
#include "filesys.h"
|
2004-07-15 21:54:48 +00:00
|
|
|
|
2004-12-13 18:55:42 +00:00
|
|
|
#include "boinc_gl.h"
|
2006-03-31 07:16:44 +00:00
|
|
|
#include "boinc_glut.h"
|
2004-12-13 18:55:42 +00:00
|
|
|
#include "graphics_api.h"
|
|
|
|
#include "graphics_impl.h"
|
|
|
|
|
2004-07-15 21:54:48 +00:00
|
|
|
#define BOINC_WINDOW_CLASS_NAME "BOINC_app"
|
|
|
|
|
2004-10-13 22:52:37 +00:00
|
|
|
#define TIMER_INTERVAL_MSEC 30
|
2007-07-31 13:07:10 +00:00
|
|
|
#define TIMER_INTERVAL_SUSPENDED_MSEC 1000
|
2004-10-13 22:52:37 +00:00
|
|
|
|
2004-07-15 21:54:48 +00:00
|
|
|
static bool visible = true;
|
|
|
|
static int current_graphics_mode = MODE_HIDE_GRAPHICS;
|
2004-10-13 20:20:19 +00:00
|
|
|
static int acked_graphics_mode;
|
|
|
|
static int xpos = 100, ypos = 100;
|
2006-08-21 14:41:30 +00:00
|
|
|
static int win_width = 600, win_height = 400;
|
2004-10-13 20:20:19 +00:00
|
|
|
static int clicked_button;
|
|
|
|
static int win=0;
|
2005-01-08 01:17:51 +00:00
|
|
|
static bool glut_is_initialized = false;
|
2007-07-31 13:07:10 +00:00
|
|
|
static bool suspend_render = false;
|
2006-08-01 23:59:33 +00:00
|
|
|
|
|
|
|
// freeglut extensions, not in GL/glut.h.
|
|
|
|
//
|
|
|
|
|
|
|
|
// glutGet(GLUT_VERSION) returns the freeglut version.
|
|
|
|
// returns (major*10000)+(minor*100)+maint level
|
|
|
|
// NOTE - make sure freeglut is initialized before
|
|
|
|
// getting the version.
|
|
|
|
// NOTE - this isn't valid in GLUT which makes it doubly
|
|
|
|
// useful, the -1 return code says its _not_
|
|
|
|
// running freeglut so makes for a useful way
|
|
|
|
// we can tell at runtime which library
|
|
|
|
// is in use.
|
|
|
|
//
|
|
|
|
#ifndef GLUT_VERSION
|
|
|
|
#define GLUT_VERSION 0x01FC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// glutGet(GLUT_INIT_STATE) returns freegluts state. Determines
|
|
|
|
// when to call glutInit again to reinitialize it.
|
2008-02-27 23:26:38 +00:00
|
|
|
//
|
2006-08-01 23:59:33 +00:00
|
|
|
#ifndef GLUT_INIT_STATE
|
|
|
|
#define GLUT_INIT_STATE 0x007C
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Simple defines for checking freeglut states
|
2008-02-27 23:26:38 +00:00
|
|
|
//
|
2006-08-01 23:59:33 +00:00
|
|
|
|
|
|
|
// Check whether freeglut is initialized. Necessary
|
|
|
|
// since it deinitializes itself when the window is
|
|
|
|
// closed. Only works with freeglut, although glut
|
|
|
|
// will return -1 and write a warning message to stdout
|
|
|
|
//
|
|
|
|
#define FREEGLUT_IS_INITIALIZED ((bool)(glutGet(GLUT_INIT_STATE)==1))
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether a window exists. Necessary as glutDestroyWindow
|
|
|
|
// causes SIGABRT, so we hide and reshow windows instead
|
|
|
|
// of creating and deleting them. (Talking freeglut here)
|
|
|
|
// note - make sure glutInit is called before checking,
|
2008-02-27 23:26:38 +00:00
|
|
|
// otherwise freeglut will SIGABRT.
|
2006-08-01 23:59:33 +00:00
|
|
|
//
|
|
|
|
#define GLUT_HAVE_WINDOW ((bool)(glutGetWindow()!=0))
|
|
|
|
|
|
|
|
|
|
|
|
// Runtime tag to tell we're using freeglut so can take precautions
|
|
|
|
// and avoid SIGABRTs. Initialize the flag to 'true' and the
|
|
|
|
// init code in boinc_glut_init() will check whether we have
|
|
|
|
// openglut or freeglut, resetting the variable as necessary.
|
2008-02-27 23:26:38 +00:00
|
|
|
//
|
2006-08-01 23:59:33 +00:00
|
|
|
// Linux systems ship with freeglut, so default is 'true' and
|
|
|
|
// its checked.
|
|
|
|
//
|
|
|
|
// If running freeglut, also get the version.
|
|
|
|
//
|
2006-08-17 09:39:18 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
static bool glut_is_freeglut = false; // Avoid warning message to stderr from glutGet(GLUT_VERSION)
|
2006-08-21 15:59:16 +00:00
|
|
|
static bool need_show = false;
|
2006-08-17 09:39:18 +00:00
|
|
|
#else
|
2006-08-01 23:59:33 +00:00
|
|
|
static bool glut_is_freeglut = true;
|
2006-08-17 09:39:18 +00:00
|
|
|
#endif
|
2006-08-01 23:59:33 +00:00
|
|
|
static int glut_version = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// State variables for freeglut windows. Since freeglut has
|
|
|
|
// problems wiht glutDestroyWindow, keep it open and just
|
|
|
|
// hide/show it as necessary.
|
|
|
|
//
|
|
|
|
static int fg_window_state; // values same as mode
|
|
|
|
static bool fg_window_is_fullscreen;
|
|
|
|
|
2006-05-04 04:29:28 +00:00
|
|
|
static jmp_buf jbuf; // longjump/setjump for exit/signal handler
|
2005-01-08 01:17:51 +00:00
|
|
|
static struct sigaction original_signal_handler; // store previous ABRT signal-handler
|
2004-10-13 20:20:19 +00:00
|
|
|
static void set_mode(int mode);
|
2005-01-08 01:17:51 +00:00
|
|
|
static void restart(void);
|
|
|
|
static void boinc_glut_init(void);
|
|
|
|
|
2004-12-13 19:14:54 +00:00
|
|
|
static APP_INIT_DATA aid;
|
2004-07-15 21:54:48 +00:00
|
|
|
|
2006-05-04 04:29:28 +00:00
|
|
|
extern pthread_t graphics_thread; // thread info
|
2005-01-08 01:17:51 +00:00
|
|
|
extern pthread_t worker_thread;
|
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
// possible longjmp-values to signal from where we jumped:
|
|
|
|
//
|
|
|
|
enum {
|
2005-01-19 15:54:04 +00:00
|
|
|
JUMP_NONE = 0,
|
|
|
|
JUMP_EXIT,
|
|
|
|
JUMP_ABORT,
|
|
|
|
JUMP_LAST
|
2005-02-15 06:32:43 +00:00
|
|
|
};
|
2005-01-19 15:54:04 +00:00
|
|
|
// 1= exit caught by atexit, 2 = signal caught by handler
|
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
int xwin_glut_is_initialized() {
|
|
|
|
return glut_is_initialized;
|
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2006-12-05 03:50:36 +00:00
|
|
|
bool debug = false;
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2004-12-13 18:55:42 +00:00
|
|
|
// This callback is invoked when a user presses a key.
|
|
|
|
//
|
2005-03-14 18:39:41 +00:00
|
|
|
void keyboardD(unsigned char key, int /*x*/, int /*y*/) {
|
2004-12-13 18:55:42 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
2005-03-14 18:39:41 +00:00
|
|
|
} else {
|
|
|
|
boinc_app_key_press((int) key, 0);
|
2004-12-13 18:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-14 18:39:41 +00:00
|
|
|
void keyboardU(unsigned char key, int /*x*/, int /*y*/) {
|
2004-10-13 20:20:19 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
2005-03-14 18:39:41 +00:00
|
|
|
} else {
|
2005-03-19 21:39:17 +00:00
|
|
|
boinc_app_key_release((int) key, 0);
|
2004-10-13 20:20:19 +00:00
|
|
|
}
|
2002-11-12 20:59:00 +00:00
|
|
|
}
|
|
|
|
|
2004-07-15 21:54:48 +00:00
|
|
|
void mouse_click(int button, int state, int x, int y){
|
2004-10-13 20:20:19 +00:00
|
|
|
clicked_button = button;
|
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
} else {
|
|
|
|
if (state) {
|
|
|
|
boinc_app_mouse_button(x, y, button, false);
|
|
|
|
} else {
|
|
|
|
boinc_app_mouse_button(x, y, button, true);
|
|
|
|
}
|
|
|
|
}
|
2004-07-15 21:54:48 +00:00
|
|
|
}
|
2002-11-12 20:59:00 +00:00
|
|
|
|
2004-07-15 21:54:48 +00:00
|
|
|
void mouse_click_move(int x, int y){
|
2004-10-13 20:20:19 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN){
|
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
} 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);
|
|
|
|
}
|
2004-07-15 21:54:48 +00:00
|
|
|
}
|
2002-11-12 20:59:00 +00:00
|
|
|
|
2007-07-31 13:35:40 +00:00
|
|
|
// maybe_render() can be called directly by GLUT when a window is
|
|
|
|
// uncovered, so we let that happen even if suspend_render is true.
|
2004-10-13 22:52:37 +00:00
|
|
|
static void maybe_render() {
|
|
|
|
int width, height;
|
2007-07-31 13:07:10 +00:00
|
|
|
BOINC_STATUS boinc_status;
|
|
|
|
|
2004-10-13 22:52:37 +00:00
|
|
|
if (visible && (current_graphics_mode != MODE_HIDE_GRAPHICS)) {
|
|
|
|
width = glutGet(GLUT_WINDOW_WIDTH);
|
|
|
|
height = glutGet(GLUT_WINDOW_HEIGHT);
|
|
|
|
if (throttled_app_render(width, height, dtime())) {
|
|
|
|
glutSwapBuffers();
|
2005-04-25 11:09:40 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
switch (current_graphics_mode) {
|
|
|
|
case MODE_WINDOW:
|
|
|
|
MacGLUTFix(false);
|
2006-08-21 15:59:16 +00:00
|
|
|
if (need_show) {
|
|
|
|
glutShowWindow();
|
|
|
|
need_show = false;
|
|
|
|
}
|
2005-04-25 11:09:40 +00:00
|
|
|
break;
|
|
|
|
case MODE_FULLSCREEN:
|
|
|
|
case MODE_BLANKSCREEN:
|
|
|
|
MacGLUTFix(true);
|
2006-08-21 15:59:16 +00:00
|
|
|
if (need_show) {
|
|
|
|
glutShowWindow();
|
|
|
|
need_show = false;
|
|
|
|
}
|
2005-04-25 11:09:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-31 13:07:10 +00:00
|
|
|
// Always render once after app is suspended in case app displays
|
|
|
|
// different graphics when suspended, then stop rendering
|
|
|
|
boinc_get_status(&boinc_status);
|
|
|
|
if (boinc_status.suspended)
|
|
|
|
suspend_render = true;
|
2004-10-13 22:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-05 11:48:52 +00:00
|
|
|
void CloseWindow() {
|
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
}
|
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
static void make_new_window(int mode) {
|
|
|
|
if ( (mode != MODE_WINDOW) && (mode != MODE_FULLSCREEN) ) {
|
|
|
|
// nothing to be done here
|
|
|
|
return;
|
|
|
|
}
|
2004-10-13 22:52:37 +00:00
|
|
|
|
2006-08-01 23:59:33 +00:00
|
|
|
if (glut_is_initialized && glut_is_freeglut) {
|
|
|
|
if (!FREEGLUT_IS_INITIALIZED) {
|
|
|
|
glut_is_initialized = false;
|
|
|
|
fg_window_is_fullscreen = false;
|
|
|
|
fg_window_state = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-02-15 06:32:43 +00:00
|
|
|
if (!glut_is_initialized) {
|
|
|
|
boinc_glut_init();
|
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "make_new_window(): now calling glutCreateWindow(%s)...\n", aid.app_name);
|
2005-10-12 02:19:28 +00:00
|
|
|
char window_title[256];
|
2005-10-12 18:40:53 +00:00
|
|
|
get_window_title(aid, window_title, 256);
|
2006-08-01 23:59:33 +00:00
|
|
|
|
|
|
|
// just show the window if its hidden
|
|
|
|
// if it used to be fullscreen (before
|
|
|
|
// it was hidden, reset size and position
|
|
|
|
// to defaults
|
|
|
|
//
|
|
|
|
bool have_window = false;
|
|
|
|
if (glut_is_freeglut && GLUT_HAVE_WINDOW) {
|
|
|
|
have_window = true;
|
|
|
|
glutShowWindow();
|
|
|
|
if (fg_window_is_fullscreen) {
|
|
|
|
glutPositionWindow(xpos, ypos);
|
|
|
|
glutReshapeWindow(600, 400);
|
|
|
|
fg_window_is_fullscreen = false;
|
|
|
|
}
|
|
|
|
fg_window_state = MODE_WINDOW;
|
|
|
|
}
|
|
|
|
|
2006-08-21 14:41:30 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
if (win)
|
|
|
|
have_window = true;
|
|
|
|
#endif
|
|
|
|
|
2006-08-01 23:59:33 +00:00
|
|
|
if (!have_window) {
|
|
|
|
win = glutCreateWindow(window_title);
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "glutCreateWindow() succeeded. win = %d\n", win);
|
2006-08-01 23:59:33 +00:00
|
|
|
|
|
|
|
glutReshapeFunc(app_graphics_resize);
|
|
|
|
glutKeyboardFunc(keyboardD);
|
|
|
|
glutKeyboardUpFunc(keyboardU);
|
|
|
|
glutMouseFunc(mouse_click);
|
|
|
|
glutMotionFunc(mouse_click_move);
|
|
|
|
glutDisplayFunc(maybe_render);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
2006-08-21 15:59:16 +00:00
|
|
|
app_graphics_init();
|
|
|
|
}
|
|
|
|
|
2005-04-05 14:26:34 +00:00
|
|
|
#ifdef __APPLE__
|
2006-08-27 00:03:58 +00:00
|
|
|
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."
|
2006-08-21 15:59:16 +00:00
|
|
|
need_show = true;
|
2005-04-05 11:48:52 +00:00
|
|
|
#endif
|
2005-04-05 14:26:34 +00:00
|
|
|
|
|
|
|
if (mode == MODE_FULLSCREEN) {
|
|
|
|
glutFullScreen();
|
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2006-10-31 00:29:30 +00:00
|
|
|
// Initialize GLUT.
|
|
|
|
// Using GLUT, this should only called once,
|
|
|
|
// even if the window is closed and opened.
|
2006-08-01 23:59:33 +00:00
|
|
|
// Using freeGLUT, its called to reinit freeglut and
|
|
|
|
// the graphics window as freeglut 'deinitialized' itself
|
|
|
|
// when the window is destroyed
|
|
|
|
//
|
|
|
|
// note - this is called from make_new_window() when a new
|
|
|
|
// window is to be created.
|
2005-02-15 06:32:43 +00:00
|
|
|
//
|
|
|
|
static void boinc_glut_init() {
|
2005-02-16 23:17:43 +00:00
|
|
|
const char* args[2] = {"screensaver", NULL};
|
2005-02-15 06:32:43 +00:00
|
|
|
int one=1;
|
2006-08-01 23:59:33 +00:00
|
|
|
static bool first = true;
|
|
|
|
|
|
|
|
win = 0;
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "Calling glutInit()... \n");
|
2005-02-16 23:17:43 +00:00
|
|
|
glutInit (&one, (char**)args);
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "survived glutInit(). \n");
|
2006-08-01 23:59:33 +00:00
|
|
|
|
|
|
|
// figure out whether we're running GLUT or freeglut.
|
|
|
|
//
|
|
|
|
// note - glutGet(GLUT_VERSION) is supported in freeglut,
|
|
|
|
// other GLUT returns -1 and outputs a warning
|
|
|
|
// message to stderr.
|
|
|
|
// - must be after glutInit or will get SIGABRT
|
|
|
|
//
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
if (glut_is_freeglut) {
|
|
|
|
glut_version = glutGet(GLUT_VERSION);
|
|
|
|
if (glut_version == -1) {
|
|
|
|
glut_version = 0;
|
|
|
|
glut_is_freeglut = false;
|
|
|
|
} else {
|
|
|
|
int major = glut_version/10000;
|
|
|
|
int minor = (glut_version -(major*10000))/100;
|
|
|
|
int maint = glut_version - (major*10000) - (minor * 100);
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "Running freeGLUT %d.%d.%d.\n", major, minor, maint);
|
2006-08-01 23:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
|
|
|
glutInitWindowPosition(xpos, ypos);
|
|
|
|
glutInitWindowSize(600, 400);
|
|
|
|
g_bmsp->boinc_get_init_data_hook(aid);
|
|
|
|
if (!strlen(aid.app_name)) {
|
2013-06-03 22:04:20 +00:00
|
|
|
strlcpy(aid.app_name, "BOINC Application", sizeof(aid.app_name));
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
glut_is_initialized = true;
|
2006-08-01 23:59:33 +00:00
|
|
|
if (glut_is_freeglut) {
|
|
|
|
fg_window_state = 0;
|
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
return;
|
2005-01-08 01:17:51 +00:00
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
|
|
|
// Destroy current window if any
|
2005-02-15 06:32:43 +00:00
|
|
|
//
|
2006-08-01 23:59:33 +00:00
|
|
|
// Note - glutDestroyWindow results in SIGABRT in freeglut, so
|
|
|
|
// instead of closing the window, just hide it. And
|
|
|
|
// before hiding it, make sure there is a window,
|
|
|
|
// user could have closed it.
|
|
|
|
//
|
2004-10-13 20:20:19 +00:00
|
|
|
void KillWindow() {
|
2006-08-01 23:59:33 +00:00
|
|
|
if (win) {
|
2006-08-21 14:41:30 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
if (current_graphics_mode == MODE_WINDOW) {
|
|
|
|
win_width = glutGet(GLUT_WINDOW_WIDTH);
|
|
|
|
win_height = glutGet(GLUT_WINDOW_HEIGHT);
|
|
|
|
xpos = glutGet(GLUT_WINDOW_X);
|
|
|
|
ypos = glutGet(GLUT_WINDOW_Y);
|
2006-08-21 15:59:16 +00:00
|
|
|
} else {
|
2006-08-22 00:53:47 +00:00
|
|
|
// If fullscreen, resize now to avoid ugly flash if we subsequently
|
|
|
|
// redisplay as MODE_WINDOW.
|
2006-08-21 15:59:16 +00:00
|
|
|
glutPositionWindow(xpos, ypos);
|
|
|
|
glutReshapeWindow(win_width, win_height);
|
2006-08-21 14:41:30 +00:00
|
|
|
}
|
2006-08-21 15:59:16 +00:00
|
|
|
|
2006-08-22 00:53:47 +00:00
|
|
|
// On Intel Macs (but not on PowerPC Macs) GLUT's destuctors often crash when
|
|
|
|
// glutDestroyWindow() is called. So far, this has only been reported for
|
|
|
|
// SETI@home. Since it doesn't occur on PowerPC Macs, we suspect a bug in GLUT.
|
|
|
|
// To work around this, we just hide the window instead. Though this does not
|
|
|
|
// free up RAM and VM used by the graphics, glutDestroyWindow() doesn't free
|
|
|
|
// them either (surprisingly), so there is no additional penalty for doing it
|
|
|
|
// this way.
|
2006-08-21 14:41:30 +00:00
|
|
|
glutHideWindow();
|
|
|
|
#else
|
2006-08-01 23:59:33 +00:00
|
|
|
if (glut_is_freeglut && FREEGLUT_IS_INITIALIZED && GLUT_HAVE_WINDOW) {
|
|
|
|
glutHideWindow();
|
|
|
|
} else {
|
|
|
|
int oldwin = win;
|
|
|
|
win = 0; // set this to 0 FIRST to avoid recursion if the following call fails.
|
|
|
|
glutDestroyWindow(oldwin);
|
|
|
|
}
|
2006-08-21 14:41:30 +00:00
|
|
|
#endif
|
2006-08-01 23:59:33 +00:00
|
|
|
}
|
2004-07-15 21:54:48 +00:00
|
|
|
}
|
2002-11-12 20:59:00 +00:00
|
|
|
|
2004-07-15 21:54:48 +00:00
|
|
|
void set_mode(int mode) {
|
2005-09-06 12:58:56 +00:00
|
|
|
if (mode == current_graphics_mode) {
|
|
|
|
// Bring graphics window to front whenever user presses "Show graphics"
|
2006-08-01 23:59:33 +00:00
|
|
|
if (mode == MODE_WINDOW) {
|
|
|
|
#ifdef __APPLE__
|
2005-09-06 12:58:56 +00:00
|
|
|
BringAppToFront();
|
2006-08-01 23:59:33 +00:00
|
|
|
#else
|
|
|
|
if (glut_is_freeglut && FREEGLUT_IS_INITIALIZED && (GLUT_HAVE_WINDOW > 0)) {
|
|
|
|
// glutPopWindow();
|
|
|
|
glutShowWindow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2005-09-06 12:58:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-01-19 15:54:04 +00:00
|
|
|
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "set_mode(%d): current_mode = %d.\n", mode, current_graphics_mode);
|
2005-09-06 12:58:56 +00:00
|
|
|
if (glut_is_initialized) {
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "Calling KillWindow(): win = %d\n", win);
|
2005-09-06 12:58:56 +00:00
|
|
|
KillWindow();
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "KillWindow() survived.\n");
|
2005-09-06 12:58:56 +00:00
|
|
|
}
|
|
|
|
|
2004-10-13 20:20:19 +00:00
|
|
|
if (mode != MODE_HIDE_GRAPHICS) {
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "set_mode(): Calling make_new_window(%d)\n", mode);
|
2005-02-15 06:32:43 +00:00
|
|
|
make_new_window(mode);
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "make_new_window() survived.\n");
|
2004-10-13 20:20:19 +00:00
|
|
|
}
|
2005-09-06 12:58:56 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
else
|
|
|
|
HideThisApp();
|
|
|
|
#endif
|
2005-01-19 15:54:04 +00:00
|
|
|
|
|
|
|
current_graphics_mode = mode;
|
|
|
|
|
2005-01-08 01:17:51 +00:00
|
|
|
return;
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
2004-10-14 22:01:05 +00:00
|
|
|
|
|
|
|
static void wait_for_initial_message() {
|
2004-12-19 07:53:02 +00:00
|
|
|
(*g_bmsp->app_client_shmp)->shm->graphics_reply.send_msg(
|
2004-10-14 22:01:05 +00:00
|
|
|
xml_graphics_modes[MODE_HIDE_GRAPHICS]
|
|
|
|
);
|
|
|
|
acked_graphics_mode = MODE_HIDE_GRAPHICS;
|
|
|
|
while (1) {
|
2004-12-19 07:53:02 +00:00
|
|
|
if ((*g_bmsp->app_client_shmp)->shm->graphics_request.has_msg()) {
|
2004-10-14 22:01:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(1);
|
2004-10-13 20:20:19 +00:00
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
return;
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
2002-11-12 20:59:00 +00:00
|
|
|
|
2004-10-13 20:20:19 +00:00
|
|
|
static void timer_handler(int) {
|
|
|
|
char buf[MSG_CHANNEL_SIZE];
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG m;
|
2007-07-31 13:07:10 +00:00
|
|
|
BOINC_STATUS boinc_status;
|
2004-10-13 20:20:19 +00:00
|
|
|
|
2004-12-19 07:53:02 +00:00
|
|
|
if (*g_bmsp->app_client_shmp) {
|
|
|
|
if ((*g_bmsp->app_client_shmp)->shm->graphics_request.get_msg(buf)) {
|
|
|
|
(*g_bmsp->app_client_shmp)->decode_graphics_msg(buf, m);
|
2004-11-17 19:19:26 +00:00
|
|
|
switch (m.mode) {
|
2004-10-13 20:20:19 +00:00
|
|
|
case MODE_REREAD_PREFS:
|
|
|
|
//only reread graphics prefs if we have a window open
|
|
|
|
//
|
|
|
|
switch (current_graphics_mode){
|
|
|
|
case MODE_WINDOW:
|
|
|
|
case MODE_FULLSCREEN:
|
|
|
|
app_graphics_reread_prefs();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_HIDE_GRAPHICS:
|
|
|
|
case MODE_WINDOW:
|
|
|
|
case MODE_FULLSCREEN:
|
|
|
|
case MODE_BLANKSCREEN:
|
2005-02-15 06:32:43 +00:00
|
|
|
if (strlen(m.display)) {
|
2008-05-06 17:10:44 +00:00
|
|
|
setenv("DISPLAY",m.display,1);
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
2004-11-17 19:19:26 +00:00
|
|
|
set_mode(m.mode);
|
2004-10-13 20:20:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (acked_graphics_mode != current_graphics_mode) {
|
2004-12-19 07:53:02 +00:00
|
|
|
bool sent = (*g_bmsp->app_client_shmp)->shm->graphics_reply.send_msg(
|
2004-10-13 20:20:19 +00:00
|
|
|
xml_graphics_modes[current_graphics_mode]
|
|
|
|
);
|
|
|
|
if (sent) acked_graphics_mode = current_graphics_mode;
|
|
|
|
}
|
2002-11-12 20:59:00 +00:00
|
|
|
}
|
2007-07-31 13:07:10 +00:00
|
|
|
boinc_get_status(&boinc_status);
|
|
|
|
if (! boinc_status.suspended)
|
|
|
|
suspend_render = false;
|
|
|
|
if (suspend_render) {
|
|
|
|
glutTimerFunc(TIMER_INTERVAL_SUSPENDED_MSEC, timer_handler, 0);
|
|
|
|
} else {
|
|
|
|
maybe_render();
|
|
|
|
glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0);
|
|
|
|
}
|
2004-10-13 22:52:37 +00:00
|
|
|
|
2005-01-08 01:17:51 +00:00
|
|
|
return;
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
2004-11-17 21:02:46 +00:00
|
|
|
|
2005-01-08 01:17:51 +00:00
|
|
|
// exit handler: really only meant to handle exits() called by GLUT...
|
2005-02-15 06:32:43 +00:00
|
|
|
//
|
|
|
|
void restart() {
|
|
|
|
// don't do anything except when exit is called from the graphics-thread
|
|
|
|
if (!pthread_equal(pthread_self(), graphics_thread)) {
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "exit() was called from worker-thread\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "restart: exit() called from graphics-thread.\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
|
|
|
|
// if we are standalone and glut was initialized,
|
|
|
|
// we assume user pressed 'close', and we exit the app
|
|
|
|
//
|
2005-04-05 11:48:52 +00:00
|
|
|
//
|
|
|
|
if (glut_is_initialized ) {
|
2006-05-04 04:29:28 +00:00
|
|
|
if (boinc_is_standalone()) {
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr,
|
2006-05-04 04:29:28 +00:00
|
|
|
"Assuming user pressed 'close'... means we're exiting now.\n"
|
|
|
|
);
|
|
|
|
if (boinc_delete_file(LOCKFILE) != 0) {
|
2005-04-05 14:26:34 +00:00
|
|
|
perror ("Failed to remove lockfile..\n");
|
2006-05-04 04:29:28 +00:00
|
|
|
}
|
2005-04-05 14:26:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// re-install the exit-handler to catch glut's notorious exits()...
|
|
|
|
//
|
|
|
|
atexit(restart);
|
|
|
|
|
|
|
|
// jump back to entry-point in xwin_graphics_event_loop();
|
|
|
|
//
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "restart: Jumping back to event_loop.\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
longjmp(jbuf, JUMP_EXIT);
|
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
|
|
|
// deal with ABORT's, typically raised by GLUT
|
2005-02-15 06:32:43 +00:00
|
|
|
// If we are in the graphics thread, we just return back
|
2004-12-29 12:21:46 +00:00
|
|
|
// into xwin_graphics_event_loop. If we are in the main thread, then
|
|
|
|
// restore the old signal handler and raise SIGABORT.
|
2005-02-15 06:32:43 +00:00
|
|
|
//
|
2005-02-16 23:17:43 +00:00
|
|
|
void restart_sig(int /*signal_number*/) {
|
2005-02-15 06:32:43 +00:00
|
|
|
if (pthread_equal(pthread_self(), graphics_thread)) {
|
|
|
|
// alternative approach is for the signal hander to call exit().
|
|
|
|
fprintf(stderr, "Caught SIGABRT in graphics thread\n");
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "Caught SIGABRT in graphics thread. Jumping back to xwin_graphics_event_loop()...\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
// jump back to entry-point in xwin_graphics_event_loop()
|
|
|
|
longjmp(jbuf, JUMP_ABORT);
|
|
|
|
} else {
|
|
|
|
// In non-graphics thread: use original signal handler
|
|
|
|
//
|
|
|
|
fprintf(stderr, "Caught SIGABRT in non-graphics thread\n");
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "Caught SIGABRT in non-graphics thread. Trying to call previous ABRT-handler...\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
if (sigaction(SIGABRT, &original_signal_handler, NULL)) {
|
2006-05-04 04:29:28 +00:00
|
|
|
perror("Unable to restore SIGABRT signal handler in non-graphics thread\n");
|
|
|
|
// what to do? call abort(3)?? call exit(nonzero)???
|
|
|
|
// Here we just return.
|
|
|
|
} else {
|
2005-02-15 06:32:43 +00:00
|
|
|
// we could conceivably try to call the old signal handler
|
|
|
|
// directly. But this means checking how its flags/masks
|
|
|
|
// are set, making sure it's not NULL (for no action) and so
|
|
|
|
// on. This seems simpler and more robust. On the other
|
|
|
|
// hand it may take some time for the signal to be
|
|
|
|
// delivered, and during that time, what's going to be
|
|
|
|
// executing?
|
|
|
|
raise(SIGABRT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-08 01:17:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
// graphics thread main-function
|
|
|
|
// NOTE: this should only be called *ONCE* by an application
|
2005-02-15 06:32:43 +00:00
|
|
|
//
|
|
|
|
void xwin_graphics_event_loop() {
|
|
|
|
int restarted = 0;
|
|
|
|
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "Direct call to xwin_graphics_event_loop()\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
|
2007-09-11 17:40:03 +00:00
|
|
|
struct sigaction sa = {0};
|
2007-09-09 21:09:07 +00:00
|
|
|
memset(&sa, 0, sizeof(sa));
|
2005-02-15 06:32:43 +00:00
|
|
|
sa.sa_handler = restart_sig;
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
|
|
|
|
// install signal handler to catch abort() from GLUT. Note that
|
|
|
|
// signal handlers are global to ALL threads, so the signal
|
|
|
|
// handler that we record here in &original_signal_handler is the
|
|
|
|
// previous one that applied to BOTH threads
|
|
|
|
if (sigaction(SIGABRT, &sa, &original_signal_handler)) {
|
|
|
|
perror("unable to install signal handler to catch SIGABORT");
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle glut's notorious exits()..
|
|
|
|
atexit(restart);
|
|
|
|
|
|
|
|
// THIS IS THE re-entry point at exit or ABORT in the graphics-thread
|
|
|
|
restarted = setjmp(jbuf);
|
|
|
|
|
|
|
|
// if we came here from an ABORT-signal thrown in this thread,
|
|
|
|
// we put this thread to sleep
|
|
|
|
//
|
|
|
|
if (restarted == JUMP_ABORT) {
|
|
|
|
while(1) {
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-01 23:59:33 +00:00
|
|
|
// If using freeglut, check to see if we need to
|
|
|
|
// reinitialize glut and graphics.
|
|
|
|
// We're only resetting flags here, actual reinit function
|
|
|
|
// is called in make_new_window().
|
|
|
|
//
|
|
|
|
if (glut_is_initialized && glut_is_freeglut) {
|
|
|
|
if (1 == (glut_is_initialized = FREEGLUT_IS_INITIALIZED)) {
|
|
|
|
if (!GLUT_HAVE_WINDOW) {
|
|
|
|
win = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
if (boinc_is_standalone()) {
|
|
|
|
if (restarted) {
|
|
|
|
while(1) {
|
2006-05-04 04:29:28 +00:00
|
|
|
sleep(1); // assuming glutInit() failed: put graphics-thread to sleep
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-05-04 04:29:28 +00:00
|
|
|
// open the graphics-window
|
2005-02-15 06:32:43 +00:00
|
|
|
set_mode(MODE_WINDOW);
|
|
|
|
glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!glut_is_initialized) {
|
2005-09-06 12:58:56 +00:00
|
|
|
#ifdef __APPLE__
|
2006-05-04 04:29:28 +00:00
|
|
|
setMacPList();
|
2005-09-06 12:58:56 +00:00
|
|
|
#endif
|
2006-05-04 04:29:28 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
while ( current_graphics_mode == MODE_HIDE_GRAPHICS ) {
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr,
|
2006-05-04 04:29:28 +00:00
|
|
|
"Graphics-thread now waiting for client-message...\n"
|
|
|
|
);
|
|
|
|
wait_for_initial_message();
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "got a graphics-message from client... \n");
|
2006-05-04 04:29:28 +00:00
|
|
|
timer_handler(0);
|
|
|
|
}
|
|
|
|
} else
|
2005-02-15 06:32:43 +00:00
|
|
|
// here glut has been initialized previously
|
|
|
|
// probably the user pressed window-'close'
|
|
|
|
//
|
2006-05-04 04:29:28 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS); // close any previously open windows
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ok we should be ready & initialized by now to call glutMainLoop()
|
|
|
|
//
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "now calling glutMainLoop()...\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
glutMainLoop();
|
2006-10-31 00:29:30 +00:00
|
|
|
if (debug) fprintf(stderr, "glutMainLoop() returned!! This should never happen...\n");
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_c457a14644 = "$Id$";
|