void wm_window_process_events(const bContext *C) { int hasevent = GHOST_ProcessEvents(g_system, 0); /* 0 is no wait */ if (hasevent) GHOST_DispatchEvents(g_system); hasevent |= wm_window_timer(C); /* no event, we sleep 5 milliseconds */ if (hasevent == 0) PIL_sleep_ms(5); }
/* exported as handle callback to bke blender.c */ void wm_window_testbreak(void) { static double ltime = 0; double curtime = PIL_check_seconds_timer(); /* only check for breaks every 50 milliseconds * if we get called more often. */ if ((curtime - ltime) > 0.05) { int hasevent = GHOST_ProcessEvents(g_system, 0); /* 0 is no wait */ if (hasevent) GHOST_DispatchEvents(g_system); ltime = curtime; } }
/* return path for restart */ static char *wm_main_playanim_intern(int argc, const char **argv) { struct ImBuf *ibuf = NULL; static char filepath[FILE_MAX]; /* abused to return dropped file path */ GHOST_TUns32 maxwinx, maxwiny; int i; /* This was done to disambiguate the name for use under c++. */ struct anim *anim = NULL; int start_x = 0, start_y = 0; int sfra = -1; int efra = -1; int totblock; PlayState ps = {0}; /* ps.doubleb = TRUE;*/ /* UNUSED */ ps.go = TRUE; ps.direction = TRUE; ps.next_frame = 1; ps.once = FALSE; ps.turbo = FALSE; ps.pingpong = FALSE; ps.noskip = FALSE; ps.sstep = FALSE; ps.wait2 = FALSE; ps.stopped = FALSE; ps.picture = NULL; ps.dropped_file[0] = 0; ps.zoom = 1.0f; /* resetmap = FALSE */ ps.fstep = 1; ps.fontid = -1; while (argc > 1) { if (argv[1][0] == '-') { switch (argv[1][1]) { case 'm': fromdisk = TRUE; break; case 'p': if (argc > 3) { start_x = atoi(argv[2]); start_y = atoi(argv[3]); argc -= 2; argv += 2; } else { printf("too few arguments for -p (need 2): skipping\n"); } break; case 'f': if (argc > 3) { double fps = atof(argv[2]); double fps_base = atof(argv[3]); if (fps == 0.0) { fps = 1; printf("invalid fps," "forcing 1\n"); } swaptime = fps_base / fps; argc -= 2; argv += 2; } else { printf("too few arguments for -f (need 2): skipping\n"); } break; case 's': sfra = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]) )); argc--; argv++; break; case 'e': efra = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]) )); argc--; argv++; break; case 'j': ps.fstep = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]))); swaptime *= ps.fstep; argc--; argv++; break; default: printf("unknown option '%c': skipping\n", argv[1][1]); break; } argc--; argv++; } else { break; } } if (argc > 1) { BLI_strncpy(filepath, argv[1], sizeof(filepath)); } else { BLI_current_working_dir(filepath, sizeof(filepath)); BLI_add_slash(filepath); } if (IMB_isanim(filepath)) { /* OCIO_TODO: support different input color spaces */ anim = IMB_open_anim(filepath, IB_rect, 0, NULL); if (anim) { ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE); IMB_close_anim(anim); anim = NULL; } } else if (!IMB_ispic(filepath)) { printf("%s: '%s' not an image file\n", __func__, filepath); exit(1); } if (ibuf == NULL) { /* OCIO_TODO: support different input color space */ ibuf = IMB_loadiffname(filepath, IB_rect, NULL); } if (ibuf == NULL) { printf("%s: '%s' couldn't open\n", __func__, filepath); exit(1); } #if 0 //XXX25 #if !defined(WIN32) && !defined(__APPLE__) if (fork()) exit(0); #endif #endif //XXX25 { GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(ghost_event_proc, &ps); g_WS.ghost_system = GHOST_CreateSystem(); GHOST_AddEventConsumer(g_WS.ghost_system, consumer); playanim_window_open("Blender:Anim", start_x, start_y, ibuf->x, ibuf->y); /* unified matrix, note it affects offset for drawing */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); } GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &maxwinx, &maxwiny); //GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); /* initialize the font */ BLF_init(11, 72); ps.fontid = BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); BLF_size(ps.fontid, 11, 72); ps.ibufx = ibuf->x; ps.ibufy = ibuf->y; ps.win_x = ps.ibufx; ps.win_y = ps.ibufy; if (maxwinx % ibuf->x) maxwinx = ibuf->x * (1 + (maxwinx / ibuf->x)); if (maxwiny % ibuf->y) maxwiny = ibuf->y * (1 + (maxwiny / ibuf->y)); glClearColor(0.1, 0.1, 0.1, 0.0); glClear(GL_COLOR_BUFFER_BIT); GHOST_SwapWindowBuffers(g_WS.ghost_window); if (sfra == -1 || efra == -1) { /* one of the frames was invalid, just use all images */ sfra = 1; efra = MAXFRAME; } build_pict_list(&ps, filepath, (efra - sfra) + 1, ps.fstep, ps.fontid); for (i = 2; i < argc; i++) { BLI_strncpy(filepath, argv[i], sizeof(filepath)); build_pict_list(&ps, filepath, (efra - sfra) + 1, ps.fstep, ps.fontid); } IMB_freeImBuf(ibuf); ibuf = NULL; pupdate_time(); ptottime = 0; /* newly added in 2.6x, without this images never get freed */ #define USE_IMB_CACHE while (ps.go) { if (ps.pingpong) ps.direction = -ps.direction; if (ps.direction == 1) { ps.picture = picsbase.first; } else { ps.picture = picsbase.last; } if (ps.picture == NULL) { printf("couldn't find pictures\n"); ps.go = FALSE; } if (ps.pingpong) { if (ps.direction == 1) { ps.picture = ps.picture->next; } else { ps.picture = ps.picture->prev; } } if (ptottime > 0.0) ptottime = 0.0; while (ps.picture) { int hasevent; #ifndef USE_IMB_CACHE if (ibuf != NULL && ibuf->ftype == 0) IMB_freeImBuf(ibuf); #endif if (ps.picture->ibuf) { ibuf = ps.picture->ibuf; } else if (ps.picture->anim) { ibuf = IMB_anim_absolute(ps.picture->anim, ps.picture->frame, IMB_TC_NONE, IMB_PROXY_NONE); } else if (ps.picture->mem) { /* use correct colorspace here */ ibuf = IMB_ibImageFromMemory((unsigned char *) ps.picture->mem, ps.picture->size, ps.picture->IB_flags, NULL, ps.picture->name); } else { /* use correct colorspace here */ ibuf = IMB_loadiffname(ps.picture->name, ps.picture->IB_flags, NULL); } if (ibuf) { #ifdef USE_IMB_CACHE ps.picture->ibuf = ibuf; #endif BLI_strncpy(ibuf->name, ps.picture->name, sizeof(ibuf->name)); /* why only windows? (from 2.4x) - campbell */ #ifdef _WIN32 GHOST_SetTitle(g_WS.ghost_window, ps.picture->name); #endif while (pupdate_time()) PIL_sleep_ms(1); ptottime -= swaptime; playanim_toscreen(&ps, ps.picture, ibuf, ps.fontid, ps.fstep); } /* else delete */ else { printf("error: can't play this image type\n"); exit(0); } if (ps.once) { if (ps.picture->next == NULL) { ps.wait2 = TRUE; } else if (ps.picture->prev == NULL) { ps.wait2 = TRUE; } } ps.next_frame = ps.direction; while ( (hasevent = GHOST_ProcessEvents(g_WS.ghost_system, 0)) || ps.wait2 != 0) { if (hasevent) { GHOST_DispatchEvents(g_WS.ghost_system); } /* Note, this still draws for mousemoves on pause */ if (ps.wait2) { if (hasevent) { if (ibuf) { while (pupdate_time()) PIL_sleep_ms(1); ptottime -= swaptime; playanim_toscreen(&ps, ps.picture, ibuf, ps.fontid, ps.fstep); } } } if (!ps.go) { break; } } ps.wait2 = ps.sstep; if (ps.wait2 == 0 && ps.stopped == 0) { ps.stopped = TRUE; } pupdate_time(); if (ps.picture && ps.next_frame) { /* always at least set one step */ while (ps.picture) { ps.picture = playanim_step(ps.picture, ps.next_frame); if (ps.once && ps.picture != NULL) { if (ps.picture->next == NULL) { ps.wait2 = TRUE; } else if (ps.picture->prev == NULL) { ps.wait2 = TRUE; } } if (ps.wait2 || ptottime < swaptime || ps.turbo || ps.noskip) break; ptottime -= swaptime; } if (ps.picture == NULL && ps.sstep) { ps.picture = playanim_step(ps.picture, ps.next_frame); } } if (ps.go == FALSE) { break; } } } ps.picture = picsbase.first; anim = NULL; while (ps.picture) { if (ps.picture && ps.picture->anim && (anim != ps.picture->anim)) { // to prevent divx crashes anim = ps.picture->anim; IMB_close_anim(anim); } if (ps.picture->ibuf) { IMB_freeImBuf(ps.picture->ibuf); } if (ps.picture->mem) { MEM_freeN(ps.picture->mem); } ps.picture = ps.picture->next; } /* cleanup */ #ifndef USE_IMB_CACHE if (ibuf) IMB_freeImBuf(ibuf); #endif BLI_freelistN(&picsbase); #if 0 // XXX25 free_blender(); #else /* we still miss freeing a lot!, * but many areas could skip initialization too for anim play */ BLF_exit(); #endif GHOST_DisposeWindow(g_WS.ghost_system, g_WS.ghost_window); /* early exit, IMB and BKE should be exited only in end */ if (ps.dropped_file[0]) { BLI_strncpy(filepath, ps.dropped_file, sizeof(filepath)); return filepath; } IMB_exit(); BKE_images_exit(); totblock = MEM_get_memory_blocks_in_use(); if (totblock != 0) { /* prints many bAKey, bArgument's which are tricky to fix */ #if 0 printf("Error Totblock: %d\n", totblock); MEM_printmemlist(); #endif } return NULL; }
void multitestapp_run(MultiTestApp *app) { while (!app->exit) { GHOST_ProcessEvents(app->sys, 1); GHOST_DispatchEvents(app->sys); } }
int main(int argc, char **argv) { GHOST_GLSettings glSettings = {0}; char *title1 = "gears - main window"; char *title2 = "gears - secondary window"; GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(processEvent, NULL); /* Create the system */ shSystem = GHOST_CreateSystem(); GHOST_AddEventConsumer(shSystem, consumer); if (shSystem) { /* Create the main window */ sMainWindow = GHOST_CreateWindow( shSystem, title1, 10, 64, 320, 200, GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, glSettings); if (!sMainWindow) { printf("could not create main window\n"); exit(-1); } /* Create a secondary window */ sSecondaryWindow = GHOST_CreateWindow( shSystem, title2, 340, 64, 320, 200, GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, glSettings); if (!sSecondaryWindow) { printf("could not create secondary window\n"); exit(-1); } /* Install a timer to have the gears running */ sGearsTimer = GHOST_InstallTimer(shSystem, 0, 10, gearsTimerProc, sMainWindow); /* Enter main loop */ while (!sExitRequested) { if (!GHOST_ProcessEvents(shSystem, 0)) { #ifdef WIN32 /* If there were no events, be nice to other applications */ Sleep(10); #endif } GHOST_DispatchEvents(shSystem); } } /* Dispose windows */ if (GHOST_ValidWindow(shSystem, sMainWindow)) { GHOST_DisposeWindow(shSystem, sMainWindow); } if (GHOST_ValidWindow(shSystem, sSecondaryWindow)) { GHOST_DisposeWindow(shSystem, sSecondaryWindow); } /* Dispose the system */ GHOST_DisposeSystem(shSystem); return 0; }
void wm_window_process_events_nosleep(void) { if (GHOST_ProcessEvents(g_system, 0)) GHOST_DispatchEvents(g_system); }