static void resize( int width, int height ) { visual_video_set_dimension( video, width, height ); SDL::create( width, height ); visual_bin_sync( bin, false ); }
static void init( int &argc, char **&argv ) { VisVideoDepth depth; visual_init( &argc, &argv ); bin = visual_bin_new (); depth = visual_video_depth_enum_from_value( 24 ); if( !plugin ) plugin = visual_actor_get_next_by_name( 0 ); if( !plugin ) exit( "Actor plugin not found!" ); visual_bin_set_supported_depth( bin, VISUAL_VIDEO_DEPTH_ALL ); if( NULL == (video = visual_video_new()) ) exit( "Cannot create a video surface" ); if( visual_video_set_depth( video, depth ) < 0 ) exit( "Cannot set video depth" ); visual_video_set_dimension( video, 320, 200 ); if( visual_bin_set_video( bin, video ) ) exit( "Cannot set video" ); visual_bin_connect_by_names( bin, (char*)plugin, 0 ); if( visual_bin_get_depth( bin ) == VISUAL_VIDEO_DEPTH_GL ) { visual_video_set_depth( video, VISUAL_VIDEO_DEPTH_GL ); pluginIsGL = true; } SDL::create( 320, 200 ); SDL_WM_SetCaption( plugin, 0 ); /* Called so the flag is set to false, seen we create the initial environment here */ visual_bin_depth_changed( bin ); VisInput *input = visual_bin_get_input( bin ); if( visual_input_set_callback( input, upload_callback, NULL ) < 0 ) exit( "Cannot set input plugin callback" ); visual_bin_switch_set_style( bin, VISUAL_SWITCH_STYLE_MORPH ); visual_bin_switch_set_automatic( bin, true ); visual_bin_switch_set_steps( bin, 100 ); visual_bin_realize( bin ); visual_bin_sync( bin, false ); std::cout << "[PANA] Libvisual version " << visual_get_version() << '\n'; std::cout << "[PANA] bpp: " << video->bpp << std::endl; std::cout << "[PANA] GL: " << (pluginIsGL ? "true\n" : "false\n"); }
static uint render() { /* On depth change */ if( visual_bin_depth_changed( bin ) ) { SDL::lock(); pluginIsGL = (visual_bin_get_depth( bin ) == VISUAL_VIDEO_DEPTH_GL); SDL::create( SDL::screen->w, SDL::screen->h ); visual_bin_sync( bin, true ); SDL::unlock(); } long ticks = -SDL_GetTicks(); if( pluginIsGL ) { visual_bin_run( bin ); SDL_GL_SwapBuffers(); } else { SDL::lock(); visual_video_set_buffer( video, SDL::screen->pixels ); visual_bin_run( bin ); SDL::unlock(); Vis::pal = visual_bin_get_palette( bin ); SDL::set_pal(); SDL_Flip( SDL::screen ); } ticks += SDL_GetTicks(); return ticks; }
int main (int argc, char **argv) { // print warm welcome std::cerr << argv[0] << " v0.1\n"; // initialize libvisual once (this is meant to be called only once, // visual_init() after visual_quit() results in undefined state) visual_log_set_verbosity(VISUAL_LOG_DEBUG); visual_init (&argc, &argv); try { // parse commandline arguments if (_parse_args(argc, argv) != EXIT_SUCCESS) throw std::runtime_error ("Failed to parse arguments"); // create new VisBin for video output VisBin *bin = visual_bin_new(); visual_bin_set_supported_depth(bin, VISUAL_VIDEO_DEPTH_ALL); visual_bin_switch_set_style(bin, VISUAL_SWITCH_STYLE_MORPH); // initialize actor plugin std::cerr << "Loading actor '" << actor_name << "'...\n"; VisActor *actor = visual_actor_new (actor_name.c_str ()); if (!actor) throw std::runtime_error ("Failed to load actor '" + actor_name + "'"); // Set random seed if (have_seed) { VisPluginData *plugin_data = visual_actor_get_plugin(actor); VisRandomContext *r_context = visual_plugin_get_random_context (plugin_data); visual_random_context_set_seed (r_context, seed); seed++; } // initialize input plugin std::cerr << "Loading input '" << input_name << "'...\n"; VisInput *input = visual_input_new(input_name.c_str()); if (!input) { throw std::runtime_error ("Failed to load input '" + input_name + "'"); } // Pick the best display depth int depthflag = visual_actor_get_supported_depth (actor); VisVideoDepth depth; if (depthflag == VISUAL_VIDEO_DEPTH_GL) { depth = visual_video_depth_get_highest (depthflag); } else { depth = visual_video_depth_get_highest_nogl (depthflag); } visual_bin_set_depth (bin, depth); VisVideoAttributeOptions const* vidoptions = visual_actor_get_video_attribute_options(actor); // initialize display SADisplay display (driver_name); // create display display.create(depth, vidoptions, width, height, true); VisVideo *video = display.get_video(); if(!video) throw std::runtime_error("Failed to get VisVideo from display"); // put it all together visual_bin_connect(bin, actor, input); visual_bin_set_video(bin, video); visual_bin_realize(bin); visual_bin_sync(bin, FALSE); visual_bin_depth_changed(bin); // get a queue to handle events VisEventQueue localqueue; // main loop bool running = true; bool visible = true; while (running) { LV::Event ev; // Handle all events display.drain_events(localqueue); LV::EventQueue* pluginqueue = visual_plugin_get_eventqueue(visual_actor_get_plugin (bin->actor)); while (localqueue.poll(ev)) { if(ev.type != VISUAL_EVENT_RESIZE) pluginqueue->add (ev); switch (ev.type) { case VISUAL_EVENT_PARAM: { break; } case VISUAL_EVENT_RESIZE: { display.lock(); width = ev.event.resize.width; height = ev.event.resize.height; display.create(depth, vidoptions, width, height, true); video = display.get_video (); visual_bin_set_video (bin, video); visual_actor_video_negotiate (bin->actor, depth, FALSE, FALSE); display.unlock(); break; } case VISUAL_EVENT_MOUSEMOTION: { break; } case VISUAL_EVENT_MOUSEBUTTONDOWN: { // switch to next actor v_cycleActor(1); v_cycleMorph(); visual_bin_set_morph_by_name(bin, morph_name.c_str()); visual_bin_switch_actor_by_name(bin, actor_name.c_str()); // get new actor actor = visual_bin_get_actor(bin); // handle depth of new actor depthflag = visual_actor_get_supported_depth(actor); if (depthflag == VISUAL_VIDEO_DEPTH_GL) { visual_bin_set_depth(bin, VISUAL_VIDEO_DEPTH_GL); } else { depth = visual_video_depth_get_highest(depthflag); if ((bin->depthflag & depth) > 0) visual_bin_set_depth(bin, depth); else visual_bin_set_depth(bin, visual_video_depth_get_highest_nogl(bin->depthflag)); } bin->depthforcedmain = bin->depth; break; } case VISUAL_EVENT_MOUSEBUTTONUP: { break; } case VISUAL_EVENT_KEYDOWN: { switch(ev.event.keyboard.keysym.sym) { case VKEY_ESCAPE: { running = false; break; } case VKEY_TAB: { break; } default: break; } break; } case VISUAL_EVENT_KEYUP: { break; } case VISUAL_EVENT_QUIT: { running = FALSE; break; } case VISUAL_EVENT_VISIBILITY: { visible = ev.event.visibility.is_visible; break; } default: { break; } } } if (visual_bin_depth_changed(bin)) { display.lock(); display.create(depth, vidoptions, width, height, true); VisVideo *video = display.get_video(); visual_bin_set_video(bin, video); visual_bin_sync(bin, TRUE); display.unlock(); } // Do a run cycle if (!visible) continue; display.lock(); visual_bin_run(bin); display.unlock(); display.update_all(); display.set_fps_limit(framerate); } } catch (std::exception& error) { std::cerr << error.what () << std::endl; } //printf ("Total frames: %d, average fps: %f\n", display_fps_total (display), display_fps_average (display)); visual_quit (); return EXIT_SUCCESS; }
/** VisBin.sync() */ JNIEXPORT void JNICALL Java_org_libvisual_android_VisBin_binSync(JNIEnv * env, jobject obj, jint bin, jboolean noevent) { VisBin *b = (VisBin *) bin; visual_bin_sync(b, noevent); }
/** VisBin.sync() */ JNIEXPORT void JNICALL Java_org_libvisual_android_VisBin_binSync(JNIEnv * env, jobject obj, jobject bin, jboolean noevent) { VisBin *b = getObjectFromCPtr<VisBin *>(env, bin); visual_bin_sync(b, noevent); }