void sawman_dispatch_tier_update( SaWMan *sawman, SaWManTier *tier, bool right_eye, const DFBRegion *updates, unsigned int num_updates ) { SaWManListenerCallData data; data.call = SWMLC_TIER_UPDATE; data.stereo_eye = right_eye ? DSSE_RIGHT : DSSE_LEFT; data.layer_id = tier->layer_id; data.num_updates = num_updates; D_ASSERT( num_updates <= D_ARRAY_SIZE(data.updates) ); direct_memcpy( data.updates, updates, num_updates * sizeof(DFBRegion) ); fusion_reactor_dispatch( sawman->reactor, &data, true, NULL ); if (!right_eye) { unsigned int i; for (i=0; i<num_updates; i++) tier->performance.pixels += (updates[i].x2 - updates[i].x1 + 1) * (updates[i].y2 - updates[i].y1 + 1); tier->performance.updates++; } }
void sawman_dispatch_blit( SaWMan *sawman, SaWManWindow *sawwin, bool right_eye, const DFBRectangle *src, const DFBRectangle *dst, const DFBRegion *clip ) { SaWManListenerCallData data; if (clip) { D_DEBUG_AT( SaWMan_Draw, "%s( %p, %d,%d-%dx%d %d,%d-%dx%d %d,%d-%dx%d )\n", __FUNCTION__, sawwin, DFB_RECTANGLE_VALS( src ), DFB_RECTANGLE_VALS( dst ), DFB_RECTANGLE_VALS_FROM_REGION( clip ) ); } else { D_DEBUG_AT( SaWMan_Draw, "%s( %p, %d,%d-%dx%d %d,%d-%dx%d NO CLIP )\n", __FUNCTION__, sawwin, DFB_RECTANGLE_VALS( src ), DFB_RECTANGLE_VALS( dst ) ); } data.call = SWMLC_WINDOW_BLIT; data.stereo_eye = right_eye ? DSSE_RIGHT : DSSE_LEFT; data.window_id = sawwin->window->id; data.resource_id = sawwin->window->resource_id; data.src = *src; data.dst = *dst; if (clip) { if (dfb_clip_blit_precheck( clip, dst->w, dst->h, dst->x, dst->y )) { dfb_clip_stretchblit( clip, &data.src, &data.dst ); fusion_reactor_dispatch( sawman->reactor, &data, true, NULL ); } else D_DEBUG_AT( SaWMan_Draw, " -> CLIPPED!\n" ); } else fusion_reactor_dispatch( sawman->reactor, &data, true, NULL ); }
int main( int argc, char *argv[] ) { DirectResult ret; pid_t child_pid; TestMessage message = {0}; FusionReactor *reactor; Reaction reaction; FusionCall call; DirectFBInit( &argc, &argv ); ret = fusion_enter( -1, 0, FER_MASTER, &m_world ); if (ret) { D_DERROR( ret, "fusion_enter() failed" ); return ret; } MSG( "Entered world %d as master (FusionID %lu, pid %d)\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); reactor = fusion_reactor_new( sizeof(TestMessage), "Test", m_world ); if (!reactor) { D_ERROR( "fusion_reactor_new() failed\n" ); return -1; } MSG( "Attaching to reactor...\n" ); ret = fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); if (ret) { D_DERROR( ret, "fusion_reactor_attach() failed" ); return ret; } MSG( ".........FORKING NOW.........\n" ); fusion_world_set_fork_action( m_world, FFA_FORK ); child_pid = fork(); fusion_world_set_fork_action( m_world, FFA_CLOSE ); switch (child_pid) { case -1: D_PERROR( "fork() failed" ); break; case 0: setsid(); MSG( "...arrived after fork() in child (pid %d)..\n", getpid() ); MSG( "..child (FusionID %lu).\n", fusion_id( m_world ) ); usleep( 400000 ); break; default: usleep( 100000 ); MSG( "...returned from fork() in parent, child pid %d.\n", child_pid ); MSG( "Initializing dispatch callback...\n" ); ret = fusion_call_init( &call, dispatch_callback, NULL, m_world ); if (ret) { D_DERROR( ret, "fusion_call_init() failed" ); return ret; } MSG( "Setting dispatch callback...\n" ); ret = fusion_reactor_set_dispatch_callback( reactor, &call, NULL ); if (ret) { D_DERROR( ret, "fusion_reactor_set_dispatch_callback() failed" ); return ret; } MSG( "Sending message via reactor...\n" ); fusion_reactor_dispatch( reactor, &message, true, NULL ); usleep( 100000 ); MSG( "Destroying reactor...\n" ); fusion_reactor_destroy( reactor ); MSG( "...destroyed reactor!\n" ); usleep( 400000 ); MSG( "Freeing reactor...\n" ); fusion_reactor_free( reactor ); MSG( "...freed reactor!\n" ); break; } MSG( "Exiting from world %d (FusionID %lu, pid %d)...\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); fusion_exit( m_world, false ); return 0; }
int main( int argc, char *argv[] ) { DirectResult ret; pid_t child_pid; TestMessage message = {0}; DirectFBInit( &argc, &argv ); ret = fusion_enter( -1, 0, FER_MASTER, &m_world ); if (ret) { D_DERROR( ret, "fusion_enter() failed" ); return ret; } MSG( "Entered world %d as master (FusionID %lu, pid %d)\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); ret = fusion_ref_init( &m_ref, "Test", m_world ); if (ret) { D_DERROR( ret, "fusion_ref_init() failed" ); return -1; } MSG( "Adding local reference...\n" ); fusion_ref_up( &m_ref, false ); m_reactor = fusion_reactor_new( sizeof(TestMessage), "Test", m_world ); if (!m_reactor) { D_ERROR( "fusion_reactor_new() failed\n" ); return -1; } MSG( "Attaching to reactor...\n" ); ret = fusion_reactor_attach( m_reactor, reaction_callback, NULL, &m_reaction ); if (ret) { D_DERROR( ret, "fusion_reactor_attach() failed" ); return ret; } MSG( ".........FORKING NOW.........\n" ); fusion_world_set_fork_action( m_world, FFA_FORK ); child_pid = fork(); fusion_world_set_fork_action( m_world, FFA_CLOSE ); switch (child_pid) { case -1: D_PERROR( "fork() failed" ); break; case 0: setsid(); MSG( "...arrived after fork() in child (pid %d)..\n", getpid() ); MSG( "..child (FusionID %lu).\n", fusion_id( m_world ) ); break; default: usleep( 200000 ); MSG( "...returned from fork() in parent, child pid %d.\n", child_pid ); break; } MSG( "Sending message via reactor...\n" ); fusion_reactor_dispatch( m_reactor, &message, true, NULL ); usleep( 200000 ); MSG( "Removing local reference...\n" ); fusion_ref_down( &m_ref, false ); usleep( 200000 ); MSG( "Exiting from world %d (FusionID %lu, pid %d)...\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); fusion_exit( m_world, false ); return 0; }
static void bench_reactor() { FusionReactor *reactor; Reaction reaction; Reaction reaction2; GlobalReaction global_reaction; reactor = fusion_reactor_new( 16, "Benchmark", world ); if (!reactor) { fprintf( stderr, "Fusion Error\n" ); return; } /* reactor attach/detach */ BENCH_START(); BENCH_LOOP() { fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); fusion_reactor_detach( reactor, &reaction ); } BENCH_STOP(); printf( "reactor attach/detach -> %8.2f k/sec\n", BENCH_RESULT() ); /* reactor attach/detach (2nd) */ fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); BENCH_START(); BENCH_LOOP() { fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction2 ); fusion_reactor_detach( reactor, &reaction2 ); } BENCH_STOP(); fusion_reactor_detach( reactor, &reaction ); printf( "reactor attach/detach (2nd) -> %8.2f k/sec\n", BENCH_RESULT() ); /* reactor attach/detach (global) */ fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); BENCH_START(); BENCH_LOOP() { fusion_reactor_attach_global( reactor, 0, NULL, &global_reaction ); fusion_reactor_detach_global( reactor, &global_reaction ); } BENCH_STOP(); fusion_reactor_detach( reactor, &reaction ); printf( "reactor attach/detach (global) -> %8.2f k/sec\n", BENCH_RESULT() ); /* reactor dispatch */ fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); BENCH_START(); BENCH_LOOP() { char msg[16]; fusion_reactor_dispatch( reactor, msg, true, NULL ); } BENCH_STOP(); printf( "reactor dispatch -> %8.2f k/sec\n", BENCH_RESULT() ); fusion_reactor_detach( reactor, &reaction ); fusion_reactor_free( reactor ); printf( "\n" ); }