From a994fe05205d1f2c60e9cf6e04b819fb0e694b7e Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Fri, 7 Jun 2002 22:47:13 +0000 Subject: [PATCH] Added basic functionality for passing graphics preferences between core and app svn path=/trunk/boinc/; revision=100 --- checkin_notes | 11 +++++++++ client/Makefile.in | 1 + client/app.C | 16 +++++++++++++ lib/gfx_interface.C | 55 +++++++++++++++++++++++++++++++++++++++++++++ lib/gfx_interface.h | 36 +++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 lib/gfx_interface.C create mode 100644 lib/gfx_interface.h diff --git a/checkin_notes b/checkin_notes index 74a0c0424a..ede9e1e7a6 100755 --- a/checkin_notes +++ b/checkin_notes @@ -394,3 +394,14 @@ Michael Gary June 07, 2002 lib/ parse.C +Eric Heien June 07, 2002 + - Added initial functionality for passing graphics preferences between core and app + + client/ + Makefile.in + app.C + lib/ + gfx_interface.C + gfx_interface.h + + diff --git a/client/Makefile.in b/client/Makefile.in index d16479f7be..2dc0fc4f69 100644 --- a/client/Makefile.in +++ b/client/Makefile.in @@ -40,6 +40,7 @@ OBJS = \ speed_stats.o \ time_stats.o \ util.o \ + ../lib/gfx_interface.o \ ../lib/parse.o \ ../lib/md5_file.o \ ../lib/md5.o diff --git a/client/app.C b/client/app.C index 61bc9743ab..b821c9ef2f 100644 --- a/client/app.C +++ b/client/app.C @@ -42,6 +42,7 @@ #include "file_names.h" #include "log_flags.h" #include "parse.h" +#include "gfx_interface.h" #include "app.h" @@ -100,7 +101,16 @@ int ACTIVE_TASK::start(bool first_time) { FILE_REF file_ref; FILE_INFO* fip; int fd, retval; + char prefs_path[256]; + FILE *prefs_fd; + GFX_INTERFACE *gi = new GFX_INTERFACE; + gi->width = 640; + gi->height = 480; + gi->depth = 32; + gi->fps = 5; + gi->draw_offscreen = 1; + gi->shared_mem_key = ftok(dirname, 'B'); // Generate a unique identifier #ifdef unix pid = fork(); @@ -131,6 +141,12 @@ int ACTIVE_TASK::start(bool first_time) { } } + // Write out the app prefs + sprintf( prefs_path, "%s/%s", dirname, "prefs.xml" ); + prefs_fd = fopen( prefs_path, "w" ); + gi->write_prefs(prefs_fd); + fclose(prefs_fd); + // create symbolic links, and hook up descriptors, for input files // for (i=0; iinput_files.size(); i++) { diff --git a/lib/gfx_interface.C b/lib/gfx_interface.C new file mode 100644 index 0000000000..0f5a6bc6d0 --- /dev/null +++ b/lib/gfx_interface.C @@ -0,0 +1,55 @@ +#include +#include +#include +#include "gfx_interface.h" +#include "parse.h" + +int GFX_INTERFACE::write_prefs(FILE *fout) { + fprintf( fout, + "\n" + " %d\n" + " %d\n" + " %d\n" + " %f\n" + " %d\n" + "", + width, height, depth, fps, shared_mem_key + ); + return 0; +} + +int GFX_INTERFACE::parse(FILE* fin) { + char buf[256]; + + fgets(buf, 256, fin); + if (!match_tag(buf, "")) { + fprintf(stderr, "GFX_INTERFACE::parse(): bad first tag %s\n", buf); + return -1; + } + + while(fgets(buf,256,fin)) { + if (match_tag(buf, "")) return 0; + else if (parse_int(buf, "", width)) continue; + else if (parse_int(buf, "", height)) continue; + else if (parse_int(buf, "", depth)) continue; + else if (parse_double(buf, "", fps)) continue; + else if (parse_int(buf, "", shared_mem_key)) continue; + else fprintf(stderr, "GFX_INTERFACE::parse(): unrecognized: %s\n", buf); + } + return -1; +} + +int GFX_INTERFACE::open_parse_prefs( void ) { + FILE *prefs; + int err; + + prefs = fopen( "prefs.xml", "r" ); + if( prefs == NULL ) + return -1; + + rewind( prefs ); + err = parse( prefs ); + fclose( prefs ); + + return err; +} diff --git a/lib/gfx_interface.h b/lib/gfx_interface.h new file mode 100644 index 0000000000..9aec1088ce --- /dev/null +++ b/lib/gfx_interface.h @@ -0,0 +1,36 @@ +#include +#include +#include + +#define DRAW_OFFSCREEN 0x01 +#define DRAW_ONSCREEN 0x02 + +// Status flags +#define ERROR -1 +#define WAITING_FOR_APP 0 +#define APP_READY 1 +#define APP_REQUEST 2 +#define BUFFER_DIRTY 3 +#define BUFFER_CLEAN 4 + +#ifndef _GFX_INTERFACE +#define _GFX_INTERFACE + +struct GFX_INTERFACE { + int width, height; // in pixels + int depth; // in bits (8. 16, 24, etc) + double fps; // max frames per second to draw (can be < 1) + int draw_offscreen; // should we draw offscreen/onscreen/anything + int shared_mem_key; // key for graphics shared memory region + int offscreen_dirty; // is the offscreen buffer ready for blitting? + + int status; // status of graphics rendering (see flags above) + char *graphicsData; + int shared_mem_allocated; + + int write_prefs(FILE*); + int parse(FILE*); + int open_parse_prefs(); +}; + +#endif _GFX_INTERFACE