static void palette_destructor( FusionObject *object, bool zombie, void *ctx ) { CorePaletteNotification notification; CorePalette *palette = (CorePalette*) object; D_MAGIC_ASSERT( palette, CorePalette ); D_DEBUG_AT( Core_Palette, "destroying %p (%d)%s\n", palette, palette->num_entries, zombie ? " (ZOMBIE)" : ""); D_ASSERT( palette->entries != NULL ); D_ASSERT( palette->entries_yuv != NULL ); notification.flags = CPNF_DESTROY; notification.palette = palette; dfb_palette_dispatch( palette, ¬ification, dfb_palette_globals ); if (palette->hash_attached) { dfb_colorhash_invalidate( NULL, palette ); dfb_colorhash_detach( NULL, palette ); } SHFREE( palette->shmpool, palette->entries_yuv ); SHFREE( palette->shmpool, palette->entries ); D_MAGIC_CLEAR( palette ); fusion_object_destroy( object ); }
static void fusion_hash_node_destroy (FusionHash *hash,FusionHashNode *node, void **old_key,void **old_value) { if (!node ) return; if ( old_key) *old_key = node->key; else if ( hash->key_type != HASH_INT ) { if (hash->free_keys) { if ( hash->local) D_FREE(node->key ); else SHFREE(hash->pool,node->key ); } } if ( old_value) *old_value = node->value; else if ( hash->value_type != HASH_INT ) { if (hash->free_values) { if ( hash->local) D_FREE(node->value ); else SHFREE(hash->pool,node->value ); } } if ( hash->local) D_FREE(node); else SHFREE(hash->pool,node); }
static DFBResult dfb_clipboard_core_shutdown( DFBClipboardCore *data, bool emergency ) { DFBClipboardCoreShared *shared; D_DEBUG_AT( Core_Clipboard, "dfb_clipboard_core_shutdown( %p, %semergency )\n", data, emergency ? "" : "no " ); D_MAGIC_ASSERT( data, DFBClipboardCore ); shared = data->shared; D_MAGIC_ASSERT( shared, DFBClipboardCoreShared ); fusion_skirmish_destroy( &shared->lock ); if (shared->data) SHFREE( shared->shmpool, shared->data ); if (shared->mime_type) SHFREE( shared->shmpool, shared->mime_type ); D_MAGIC_CLEAR( data ); D_MAGIC_CLEAR( shared ); return DFB_OK; }
void dfb_surfacemanager_destroy( SurfaceManager *manager ) { Chunk *chunk; D_ASSERT( manager != NULL ); D_ASSERT( manager->chunks != NULL ); D_MAGIC_ASSERT( manager, SurfaceManager ); D_MAGIC_CLEAR( manager ); /* Deallocate all chunks. */ chunk = manager->chunks; while (chunk) { Chunk *next = chunk->next; D_MAGIC_CLEAR( chunk ); SHFREE( chunk ); chunk = next; } /* Destroy manager lock. */ fusion_skirmish_destroy( &manager->lock ); /* Deallocate manager struct. */ SHFREE( manager ); }
static Chunk* free_chunk( SurfaceManager *manager, Chunk *chunk ) { D_MAGIC_ASSERT( manager, SurfaceManager ); D_MAGIC_ASSERT( chunk, _Chunk_ ); if (!chunk->buffer) { D_BUG( "freeing free chunk" ); return chunk; } else { D_DEBUG_AT( Core_SM, "Deallocating %d bytes at offset %d.\n", chunk->length, chunk->offset ); } if (chunk->buffer->policy == CSP_VIDEOONLY) manager->available += chunk->length; chunk->buffer = NULL; manager->min_toleration--; if (chunk->prev && !chunk->prev->buffer) { Chunk *prev = chunk->prev; //D_DEBUG_AT( Core_SM, " -> merging with previous chunk at %d\n", prev->offset ); prev->length += chunk->length; prev->next = chunk->next; if (prev->next) prev->next->prev = prev; //D_DEBUG_AT( Core_SM, " -> freeing %p (prev %p, next %p)\n", chunk, chunk->prev, chunk->next); D_MAGIC_CLEAR( chunk ); SHFREE( chunk ); chunk = prev; } if (chunk->next && !chunk->next->buffer) { Chunk *next = chunk->next; //D_DEBUG_AT( Core_SM, " -> merging with next chunk at %d\n", next->offset ); chunk->length += next->length; chunk->next = next->next; if (chunk->next) chunk->next->prev = chunk; D_MAGIC_CLEAR( next ); SHFREE( next ); } return chunk; }
DFBResult dfb_clipboard_set( DFBClipboardCore *core, const char *mime_type, const void *data, unsigned int size, struct timeval *timestamp ) { DFBClipboardCoreShared *shared; char *new_mime; void *new_data; D_MAGIC_ASSERT( core, DFBClipboardCore ); D_ASSERT( mime_type != NULL ); D_ASSERT( data != NULL ); D_ASSERT( size > 0 ); shared = core->shared; D_MAGIC_ASSERT( shared, DFBClipboardCoreShared ); new_mime = SHSTRDUP( shared->shmpool, mime_type ); if (!new_mime) return D_OOSHM(); new_data = SHMALLOC( shared->shmpool, size ); if (!new_data) { SHFREE( shared->shmpool, new_mime ); return D_OOSHM(); } direct_memcpy( new_data, data, size ); if (fusion_skirmish_prevail( &shared->lock )) { SHFREE( shared->shmpool, new_data ); SHFREE( shared->shmpool, new_mime ); return DFB_FUSION; } if (shared->data) SHFREE( shared->shmpool, shared->data ); if (shared->mime_type) SHFREE( shared->shmpool, shared->mime_type ); shared->mime_type = new_mime; shared->data = new_data; shared->size = size; gettimeofday( &shared->timestamp, NULL ); if (timestamp) *timestamp = shared->timestamp; fusion_skirmish_dismiss( &shared->lock ); return DFB_OK; }
static DFBResult init_bridge( CoreDFB *core, CoreSurfacePoolBridge *bridge, const SurfacePoolBridgeFuncs *funcs, void *context ) { DFBResult ret; D_MAGIC_ASSERT( bridge, CoreSurfacePoolBridge ); D_ASSERT( funcs != NULL ); D_ASSERT( funcs->InitPoolBridge != NULL ); D_DEBUG_AT( Core_SurfPoolBridge, "%s( %p, %p )\n", __FUNCTION__, bridge, funcs ); if (funcs->PoolBridgeDataSize) bridge->bridge_data_size = funcs->PoolBridgeDataSize(); if (funcs->PoolBridgeLocalDataSize) bridge->bridge_local_data_size = funcs->PoolBridgeLocalDataSize(); if (funcs->PoolTransferDataSize) bridge->transfer_data_size = funcs->PoolTransferDataSize(); /* Allocate shared bridge data. */ if (bridge->bridge_data_size) { bridge->data = SHCALLOC( bridge->shmpool, 1, bridge->bridge_data_size ); if (!bridge->data) return D_OOSHM(); } /* Allocate local bridge data. */ if (bridge->bridge_local_data_size && !(bridge_locals[bridge->bridge_id] = D_CALLOC( 1, bridge->bridge_local_data_size ))) { SHFREE( bridge->shmpool, bridge->data ); return D_OOM(); } ret = funcs->InitPoolBridge( core, bridge, bridge->data, get_local(bridge), context, &bridge->desc ); if (ret) { D_DERROR( ret, "Core/SurfacePoolBridge: Initializing '%s' failed!\n", bridge->desc.name ); if (bridge_locals[bridge->bridge_id]) { D_FREE( bridge_locals[bridge->bridge_id] ); bridge_locals[bridge->bridge_id] = NULL; } if (bridge->data) { SHFREE( bridge->shmpool, bridge->data ); bridge->data = NULL; } return ret; } fusion_skirmish_init2( &bridge->lock, bridge->desc.name, dfb_core_world(core), fusion_config->secure_fusion ); return DFB_OK; }
static DFBResult system_initialize( CoreDFB *core, void **ret_data ) { DFBResult ret; PVR2DData *data; PVR2DDataShared *shared; FusionSHMPoolShared *pool; D_ASSERT( m_data == NULL ); data = D_CALLOC( 1, sizeof(PVR2DData) ); if (!data) return D_OOM(); data->core = core; pool = dfb_core_shmpool( core ); shared = SHCALLOC( pool, 1, sizeof(PVR2DDataShared) ); if (!shared) { D_FREE( data ); return D_OOSHM(); } shared->shmpool = pool; data->shared = shared; ret = InitPVR2D( data ); if (ret) { SHFREE( pool, shared ); D_FREE( data ); return ret; } ret = InitEGL( data ); if (ret) { SHFREE( pool, shared ); D_FREE( data ); return ret; } *ret_data = m_data = data; data->screen = dfb_screens_register( NULL, data, pvr2dPrimaryScreenFuncs ); data->layer = dfb_layers_register( data->screen, data, pvr2dPrimaryLayerFuncs ); dfb_surface_pool_initialize( core, pvr2dSurfacePoolFuncs, &shared->pool ); fusion_arena_add_shared_field( dfb_core_arena( core ), "pvr2d", shared ); return DFB_OK; }
/** * hash_replace: * @hash: a #FusionHash. * @key: a key to insert. * @value: the value to associate with the key. * * Inserts a new key and value into a #FusionHash similar to * hash_insert(). The difference is that if the key already exists * in the #FusionHash, it gets replaced by the new key. * If you supplied a oldkey pointer or oldkey value they are returned * otherwise free is called the key if table type is not type HASH_INT * and free is called on the old value if not supplied **/ DirectResult fusion_hash_replace (FusionHash *hash, void * key, void * value, void **old_key, void **old_value) { FusionHashNode **node; D_MAGIC_ASSERT( hash, FusionHash ); node = fusion_hash_lookup_node (hash, key); if (*node) { if ( old_key) *old_key = (*node)->key; else if ( hash->key_type != HASH_INT ) { if (hash->free_keys) { if (hash->local) D_FREE((*node)->key); else SHFREE(hash->pool, (*node)->key ); } } if ( old_value) *old_value = (*node)->value; else if ( hash->value_type != HASH_INT ) { if (hash->free_values) { if (hash->local) D_FREE((*node)->value); else SHFREE(hash->pool, (*node)->value ); } } } else { if (hash->local) *node = D_CALLOC(1, sizeof(FusionHashNode)); else *node = SHCALLOC(hash->pool, 1, sizeof(FusionHashNode)); if ( !(*node) ) return hash->local?DFB_NOSYSTEMMEMORY:DFB_NOSHAREDMEMORY; hash->nnodes++; } (*node)->key = (void*)key; (*node)->value = (void*)value; return DFB_OK; }
static DFBResult dfb_rtd_set_video_mode( CoreDFB *core, CoreLayerRegionConfig *config ) { int ret; CoreLayerRegionConfig *tmp = NULL; D_ASSERT( config != NULL ); if (dfb_core_is_master( core )) return dfb_rtd_set_video_mode_handler( config ); if (!fusion_is_shared( dfb_core_world(core), config )) { tmp = SHMALLOC( dfb_core_shmpool(core), sizeof(CoreLayerRegionConfig) ); if (!tmp) return D_OOSHM(); direct_memcpy( tmp, config, sizeof(CoreLayerRegionConfig) ); } fusion_call_execute( &dfb_rtd->call, FCEF_NONE, RTD_SET_VIDEO_MODE, tmp ? tmp : config, &ret ); if (tmp) SHFREE( dfb_core_shmpool(core), tmp ); return ret; }
static DFBResult x11DeallocateBuffer( CoreSurfacePool *pool, void *pool_data, void *pool_local, CoreSurfaceBuffer *buffer, CoreSurfaceAllocation *allocation, void *alloc_data ) { x11AllocationData *alloc = alloc_data; x11PoolLocalData *local = pool_local; DFBX11 *x11 = local->x11; DFBX11Shared *shared = x11->shared; D_DEBUG_AT( X11_Surfaces, "%s()\n", __FUNCTION__ ); D_MAGIC_ASSERT( pool, CoreSurfacePool ); D_MAGIC_ASSERT( buffer, CoreSurfaceBuffer ); CORE_SURFACE_ALLOCATION_ASSERT( allocation ); if (alloc->ptr) SHFREE( shared->data_shmpool, alloc->ptr ); return DFB_OK; }
static DFBResult dfb_rtd_update_screen( CoreDFB *core, DFBRegion *region ) { int ret; DFBRegion *tmp = NULL; if (dfb_core_is_master( core )) return dfb_rtd_update_screen_handler( region ); if (region) { if (!fusion_is_shared( dfb_core_world(core), region )) { tmp = SHMALLOC( dfb_core_shmpool(core), sizeof(DFBRegion) ); if (!tmp) return D_OOSHM(); direct_memcpy( tmp, region, sizeof(DFBRegion) ); } } fusion_call_execute( &dfb_rtd->call, FCEF_NONE, RTD_UPDATE_SCREEN, tmp ? tmp : region, &ret ); if (tmp) SHFREE( dfb_core_shmpool(core), tmp ); return DFB_OK; }
void dfb_colorhash_detach( DFBColorHashCore *core, CorePalette *palette ) { DFBColorHashCoreShared *shared; D_ASSUME( core != NULL ); if (core) { D_MAGIC_ASSERT( core, DFBColorHashCore ); D_MAGIC_ASSERT( core->shared, DFBColorHashCoreShared ); } else core = core_colorhash; shared = core->shared; D_ASSERT( shared->hash_users > 0 ); D_ASSERT( shared->hash != NULL ); fusion_skirmish_prevail( &shared->hash_lock ); shared->hash_users--; if (!shared->hash_users) { /* no more users, free allocated resources */ SHFREE( shared->shmpool, shared->hash ); shared->hash = NULL; } fusion_skirmish_dismiss( &shared->hash_lock ); }
static DFBResult system_shutdown( bool emergency ) { DFBResult ret; // for now just crash until we implement a clean shutdown crashme(); AndroidDataShared *shared; D_ASSERT( m_data != NULL ); shared = m_data->shared; D_ASSERT( shared != NULL ); dfb_surface_pool_destroy( shared->pool ); /* cleanup EGL related stuff */ eglDestroyContext( m_data->dpy, m_data->ctx ); eglTerminate( m_data->dpy ); SHFREE( shared->shmpool, shared ); D_FREE( m_data ); m_data = NULL; return DFB_OK; }
DFBResult dfb_core_part_shutdown( CoreDFB *core, CorePart *core_part, bool emergency ) { DFBResult ret; FusionSHMPoolShared *pool; pool = dfb_core_shmpool( core ); if (!core_part->initialized) return DFB_OK; D_DEBUG_AT( Core_Parts, "Going to shutdown '%s' core...\n", core_part->name ); ret = core_part->Shutdown( core_part->data_local, emergency ); if (ret) D_ERROR( "DirectFB/Core: Could not shutdown '%s' core!\n" " --> %s\n", core_part->name, DirectFBErrorString( ret ) ); if (core_part->data_shared) SHFREE( pool, core_part->data_shared ); if (core_part->data_local) D_FREE( core_part->data_local ); core_part->data_local = NULL; core_part->data_shared = NULL; core_part->initialized = false; return DFB_OK; }
static DFBResult unrealize_region( CoreLayerRegion *region ) { DFBResult ret; int index; CoreLayer *layer; CoreLayerShared *shared; const DisplayLayerFuncs *funcs; D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); D_ASSERT( D_FLAGS_IS_SET( region->state, CLRSF_REALIZED ) ); layer = dfb_layer_at( region->context->layer_id ); D_ASSERT( layer != NULL ); D_ASSERT( layer->shared != NULL ); D_ASSERT( layer->funcs != NULL ); shared = layer->shared; funcs = layer->funcs; D_ASSERT( fusion_vector_contains( &shared->added_regions, region ) ); index = fusion_vector_index_of( &shared->added_regions, region ); D_DEBUG_AT( Core_Layers, "Removing region (%d, %d - %dx%d) from '%s'.\n", DFB_RECTANGLE_VALS( ®ion->config.dest ), shared->description.name ); /* Remove the region from hardware and driver. */ if (funcs->RemoveRegion) { ret = funcs->RemoveRegion( layer, layer->driver_data, layer->layer_data, region->region_data ); if (ret) { D_DERROR( ret, "Core/Layers: Could not remove region!\n" ); return ret; } } /* Remove the region from the 'added' list. */ fusion_vector_remove( &shared->added_regions, index ); /* Deallocate the driver's region data. */ if (region->region_data) { SHFREE( shared->shmpool, region->region_data ); region->region_data = NULL; } /* Update the region's state. */ D_FLAGS_CLEAR( region->state, CLRSF_REALIZED ); D_FLAGS_SET( region->state, CLRSF_FROZEN ); if (region->surface && region->surface_lock.buffer) { dfb_surface_unlock_buffer( region->surface, ®ion->surface_lock ); dfb_surface_destroy_buffers( region->surface ); } return DFB_OK; }
static void bench_shmpool( bool debug ) { DirectResult ret; void *mem[256]; const int sizes[8] = { 12, 36, 200, 120, 39, 3082, 8, 1040 }; FusionSHMPoolShared *pool; ret = fusion_shm_pool_create( world, "Benchmark Pool", 524288, debug, &pool ); if (ret) { DirectFBError( "fusion_shm_pool_create() failed", ret ); return; } BENCH_START(); BENCH_LOOP() { int i; for (i=0; i<128; i++) mem[i] = SHMALLOC( pool, sizes[i&7] ); for (i=0; i<64; i++) SHFREE( pool, mem[i] ); for (i=128; i<192; i++) mem[i] = SHMALLOC( pool, sizes[i&7] ); for (i=64; i<128; i++) SHFREE( pool, mem[i] ); for (i=192; i<256; i++) mem[i] = SHMALLOC( pool, sizes[i&7] ); for (i=128; i<256; i++) SHFREE( pool, mem[i] ); } BENCH_STOP(); printf( "shm pool alloc/free %s -> %8.2f k/sec\n", debug ? "(debug)" : " ", BENCH_RESULT_BY(256) ); fusion_shm_pool_destroy( world, pool ); }
static DFBResult system_shutdown( bool emergency ) { FusionSHMPoolShared *pool; D_ASSERT( dfb_sdl != NULL ); /* Stop update thread. */ if (dfb_sdl->update.thread) { if (!emergency) { dfb_sdl->update.quit = true; pthread_cond_signal( &dfb_sdl->update.cond ); direct_thread_join( dfb_sdl->update.thread ); } direct_thread_destroy( dfb_sdl->update.thread ); } dfb_surface_pool_destroy( dfb_sdl->sdl_pool ); fusion_call_destroy( &dfb_sdl->call ); fusion_skirmish_prevail( &dfb_sdl->lock ); SDL_Quit(); fusion_skirmish_destroy( &dfb_sdl->lock ); pool = dfb_core_shmpool(dfb_sdl_core); while (dfb_sdl->modes) { VideoMode *next = dfb_sdl->modes->next; SHFREE( pool, dfb_sdl->modes ); dfb_sdl->modes = next; } SHFREE( pool, dfb_sdl ); dfb_sdl = NULL; dfb_sdl_core = NULL; return DFB_OK; }
static DFBResult system_shutdown( bool emergency ) { DFBX11 *x11 = dfb_system_data(); DFBX11Shared *shared = x11->shared; int i; D_DEBUG_AT( X11_Core, "%s()\n", __FUNCTION__ ); //dfb_x11_eglimpl_unregister(); /* * Master deinit */ if (shared->x11_pool_bridge) dfb_surface_pool_bridge_destroy( shared->x11_pool_bridge ); if (shared->vpsmem_pool) dfb_surface_pool_destroy( shared->vpsmem_pool ); if (shared->glx_pool) dfb_surface_pool_destroy( shared->glx_pool ); if (shared->x11window_pool) dfb_surface_pool_destroy( shared->x11window_pool ); if (shared->x11image_pool) dfb_surface_pool_destroy( shared->x11image_pool ); /* * Shared deinit (master only) */ fusion_call_destroy( &shared->call ); /* close remaining windows */ for( i=0; i<shared->outputs; i++ ) { dfb_x11_close_window( x11, shared->output[i].xw ); } SHFREE( dfb_core_shmpool( x11->core ), shared ); /* * Local deinit (master and slave) */ if (x11->display) XCloseDisplay( x11->display ); D_FREE( x11 ); return DFB_OK; }
static DFBResult x11DeallocateBuffer( CoreSurfacePool *pool, void *pool_data, void *pool_local, CoreSurfaceBuffer *buffer, CoreSurfaceAllocation *allocation, void *alloc_data ) { x11AllocationData *alloc = alloc_data; x11PoolLocalData *local = pool_local; DFBX11 *x11 = local->x11; DFBX11Shared *shared = x11->shared; void *addr; D_DEBUG_AT( X11_Surfaces, "%s()\n", __FUNCTION__ ); D_MAGIC_ASSERT( pool, CoreSurfacePool ); CORE_SURFACE_ALLOCATION_ASSERT( allocation ); switch (alloc->type) { case X11_ALLOC_PIXMAP: case X11_ALLOC_WINDOW: if (allocation->type & CSTF_PREALLOCATED) { // don't delete } else XFreePixmap( x11->display, alloc->xid ); break; case X11_ALLOC_IMAGE: x11ImageDestroy( x11, &alloc->image ); // FIXME: also detach in other processes! (e.g. via reactor) addr = direct_hash_lookup( local->hash, alloc->image.seginfo.shmid ); if (addr) { x11ImageDetach( &alloc->image, addr ); direct_hash_remove( local->hash, alloc->image.seginfo.shmid ); } break; case X11_ALLOC_SHM: if (alloc->ptr) SHFREE( shared->data_shmpool, alloc->ptr ); break; default: D_BUG( "unexpected allocation type %d\n", alloc->type ); return DFB_BUG; } return DFB_OK; }
static DFBResult system_initialize( CoreDFB *core, void **ret_data ) { DFBResult ret; DevMemData *data; DevMemDataShared *shared; FusionSHMPoolShared *pool; D_ASSERT( m_data == NULL ); if (!dfb_config->video_phys || !dfb_config->video_length) { D_ERROR( "System/DevMem: Please supply 'video-phys = 0xXXXXXXXX' and 'video-length = XXXX' options!\n" ); return DFB_INVARG; } if (dfb_config->mmio_phys && !dfb_config->mmio_length) { D_ERROR( "System/DevMem: Please supply both 'mmio-phys = 0xXXXXXXXX' and 'mmio-length = XXXX' options or none!\n" ); return DFB_INVARG; } data = D_CALLOC( 1, sizeof(DevMemData) ); if (!data) return D_OOM(); pool = dfb_core_shmpool( core ); shared = SHCALLOC( pool, 1, sizeof(DevMemDataShared) ); if (!shared) { D_FREE( data ); return D_OOSHM(); } shared->shmpool = pool; data->shared = shared; ret = MapMemAndReg( data, dfb_config->video_phys, dfb_config->video_length, dfb_config->mmio_phys, dfb_config->mmio_length ); if (ret) { SHFREE( pool, shared ); D_FREE( data ); return ret; } *ret_data = m_data = data; dfb_surface_pool_initialize( core, &devmemSurfacePoolFuncs, &shared->pool ); fusion_arena_add_shared_field( dfb_core_arena( core ), "devmem", shared ); return DFB_OK; }
static void region_destructor( FusionObject *object, bool zombie ) { CoreLayerRegion *region = (CoreLayerRegion*) object; CoreLayerContext *context = region->context; CoreLayer *layer = dfb_layer_at( context->layer_id ); CoreLayerShared *shared = layer->shared; (void) shared; D_DEBUG_AT( Core_Layers, "destroying region %p (%s, %dx%d, " "%s, %s, %s, %s%s)\n", region, shared->description.name, region->config.width, region->config.height, D_FLAGS_IS_SET( region->state, CLRSF_CONFIGURED ) ? "configured" : "unconfigured", D_FLAGS_IS_SET( region->state, CLRSF_ENABLED ) ? "enabled" : "disabled", D_FLAGS_IS_SET( region->state, CLRSF_ACTIVE ) ? "active" : "inactive", D_FLAGS_IS_SET( region->state, CLRSF_REALIZED ) ? "realized" : "not realized", zombie ? " - ZOMBIE" : "" ); /* Hide region etc. */ if (D_FLAGS_IS_SET( region->state, CLRSF_ENABLED )) dfb_layer_region_disable( region ); /* Remove the region from the context. */ dfb_layer_context_remove_region( region->context, region ); /* Throw away its surface. */ if (region->surface) { /* Detach the global listener. */ dfb_surface_detach_global( region->surface, ®ion->surface_reaction ); /* Unlink from structure. */ dfb_surface_unlink( ®ion->surface ); } /* Unlink the context from the structure. */ dfb_layer_context_unlink( ®ion->context ); /* Free driver's region data. */ if (region->region_data) SHFREE( region->region_data ); /* Deinitialize the lock. */ fusion_skirmish_destroy( ®ion->lock ); /* Destroy the object. */ fusion_object_destroy( object ); }
static int dfb_core_arena_initialize( FusionArena *arena, void *ctx ) { DFBResult ret; CoreDFB *core = ctx; CoreDFBShared *shared; FusionSHMPoolShared *pool; D_MAGIC_ASSERT( core, CoreDFB ); D_DEBUG_AT( DirectFB_Core, "Initializing...\n" ); /* Create the shared memory pool first! */ ret = fusion_shm_pool_create( core->world, "DirectFB Main Pool", 0x400000, fusion_config->debugshm, &pool ); if (ret) return ret; /* Allocate shared structure in the new pool. */ shared = SHCALLOC( pool, 1, sizeof(CoreDFBShared) ); if (!shared) { fusion_shm_pool_destroy( core->world, pool ); return D_OOSHM(); } core->shared = shared; core->master = true; shared->shmpool = pool; D_MAGIC_SET( shared, CoreDFBShared ); /* Initialize. */ ret = dfb_core_initialize( core ); if (ret) { D_MAGIC_CLEAR( shared ); SHFREE( pool, shared ); fusion_shm_pool_destroy( core->world, pool ); return ret; } fusion_skirmish_init( &shared->lock, "DirectFB Core", core->world ); CoreDFB_Init_Dispatch( core, core, &shared->call ); fusion_call_add_permissions( &shared->call, 0, FUSION_CALL_PERMIT_EXECUTE ); /* Register shared data. */ fusion_arena_add_shared_field( arena, "Core/Shared", shared ); return DFB_OK; }
DFBResult dfb_core_part_initialize( CoreDFB *core, CorePart *core_part ) { DFBResult ret; void *local = NULL; void *shared = NULL; FusionSHMPoolShared *pool; pool = dfb_core_shmpool( core ); if (core_part->initialized) { D_BUG( "%s already initialized", core_part->name ); return DFB_BUG; } D_DEBUG_AT( Core_Parts, "Going to initialize '%s' core...\n", core_part->name ); if (core_part->size_local) local = D_CALLOC( 1, core_part->size_local ); if (core_part->size_shared) shared = SHCALLOC( pool, 1, core_part->size_shared ); D_INFO("Going to initialize '%s' core...\n", core_part->name ); ret = core_part->Initialize( core, local, shared ); D_INFO("Core '%s' initialized ...\n", core_part->name ); if (ret) { D_ERROR( "DirectFB/Core: Could not initialize '%s' core!\n" " --> %s\n", core_part->name, DirectFBErrorString( ret ) ); if (shared) SHFREE( pool, shared ); if (local) D_FREE( local ); return ret; } if (shared) fusion_arena_add_shared_field( dfb_core_arena( core ), core_part->name, shared ); core_part->data_local = local; core_part->data_shared = shared; core_part->initialized = true; return DFB_OK; }
static void surface_destructor( FusionObject *object, bool zombie, void *ctx ) { int i; CoreSurface *surface = (CoreSurface*) object; D_MAGIC_ASSERT( surface, CoreSurface ); D_DEBUG_AT( Core_Surface, "destroying %p (%dx%d%s)\n", surface, surface->config.size.w, surface->config.size.h, zombie ? " ZOMBIE" : ""); Core_Resource_RemoveSurface( surface ); CoreSurface_Deinit_Dispatch( &surface->call ); dfb_surface_lock( surface ); surface->state |= CSSF_DESTROYED; /* announce surface destruction */ dfb_surface_notify( surface, CSNF_DESTROY ); /* unlink palette */ if (surface->palette) { dfb_palette_detach_global( surface->palette, &surface->palette_reaction ); dfb_palette_unlink( &surface->palette ); } /* destroy buffers */ for (i=0; i<MAX_SURFACE_BUFFERS; i++) { if (surface->buffers[i]) dfb_surface_buffer_decouple( surface->buffers[i] ); } dfb_system_surface_data_destroy( surface, surface->data ); /* release the system driver specific surface data */ if (surface->data) { SHFREE( surface->shmpool, surface->data ); surface->data = NULL; } direct_serial_deinit( &surface->serial ); dfb_surface_unlock( surface ); fusion_skirmish_destroy( &surface->lock ); D_MAGIC_CLEAR( surface ); fusion_object_destroy( object ); }
static DFBResult system_initialize( CoreDFB *core, void **data ) { char *driver; CoreScreen *screen; D_ASSERT( dfb_sdl == NULL ); dfb_sdl = (DFBSDL*) SHCALLOC( dfb_core_shmpool(core), 1, sizeof(DFBSDL) ); if (!dfb_sdl) { D_ERROR( "DirectFB/SDL: Couldn't allocate shared memory!\n" ); return D_OOSHM(); } dfb_sdl_core = core; dfb_fbdev_read_modes(); /* use same mode list as a fake */ driver = getenv( "SDL_VIDEODRIVER" ); if (driver && !strcasecmp( driver, "directfb" )) { D_INFO( "DirectFB/SDL: SDL_VIDEODRIVER is 'directfb', unsetting it.\n" ); unsetenv( "SDL_VIDEODRIVER" ); } /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { D_ERROR( "DirectFB/SDL: Couldn't initialize SDL: %s\n", SDL_GetError() ); SHFREE( dfb_core_shmpool(core), dfb_sdl ); dfb_sdl = NULL; return DFB_INIT; } fusion_skirmish_init( &dfb_sdl->lock, "SDL System", dfb_core_world(core) ); fusion_call_init( &dfb_sdl->call, dfb_sdl_call_handler, NULL, dfb_core_world(core) ); screen = dfb_screens_register( NULL, NULL, sdlPrimaryScreenFuncs ); dfb_layers_register( screen, NULL, sdlPrimaryLayerFuncs ); fusion_arena_add_shared_field( dfb_core_arena( core ), "sdl", dfb_sdl ); dfb_surface_pool_initialize( core, &sdlSurfacePoolFuncs, &dfb_sdl->sdl_pool ); *data = dfb_sdl; return DFB_OK; }
void fusion_hash_destroy( FusionHash *hash ) { int i; FusionHashNode *node, *next; D_MAGIC_ASSERT( hash, FusionHash ); for (i = 0; i < hash->size; i++) { for (node = hash->nodes[i]; node; node = next) { next = node->next; fusion_hash_node_destroy(hash, node, NULL, NULL); } } if (hash->local) D_FREE(hash->nodes); else SHFREE( hash->pool, hash->nodes ); D_MAGIC_CLEAR( hash ); if (hash->local) D_FREE(hash); else SHFREE( hash->pool, hash ); }
static void deallocate_transfer( CoreSurfacePoolTransfer *transfer ) { CoreSurfacePoolBridge *bridge; D_MAGIC_ASSERT( transfer, CoreSurfacePoolTransfer ); bridge = transfer->bridge; D_MAGIC_ASSERT( bridge, CoreSurfacePoolBridge ); D_MAGIC_CLEAR( transfer ); SHFREE( bridge->shmpool, transfer ); }
static DirectResult fusion_hash_create_internal (bool local,FusionSHMPoolShared *pool, FusionHashType key_type, FusionHashType value_type, int size, FusionHash **ret_hash ) { FusionHash *hash; if (!ret_hash) return DFB_BUG; if (!local && !pool) return DFB_BUG; if (size < FUSION_HASH_MIN_SIZE) size = FUSION_HASH_MIN_SIZE; if (local) hash = D_CALLOC(1, sizeof (FusionHash) ); else hash = SHCALLOC(pool, 1, sizeof (FusionHash) ); if (!hash) return local ?DFB_NOSYSTEMMEMORY:DFB_NOSHAREDMEMORY; hash->local = local; hash->pool = pool; hash->key_type = key_type; hash->value_type = value_type; hash->size = size; hash->nnodes = 0; if (local) hash->nodes = D_CALLOC(size,sizeof (FusionHashNode*) ); else hash->nodes = SHCALLOC(pool, size, sizeof(FusionHashNode*) ); if (!hash->nodes) { if (local) D_FREE(hash ); else SHFREE(pool, hash ); return local?DFB_NOSYSTEMMEMORY:DFB_NOSHAREDMEMORY; } D_MAGIC_SET(hash, FusionHash ); *ret_hash = hash; return DFB_OK; }
DFBResult dfb_palette_create( CoreDFB *core, unsigned int size, CorePalette **ret_palette ) { CorePalette *palette; D_DEBUG_AT( Core_Palette, "%s( %d )\n", __FUNCTION__, size ); D_ASSERT( ret_palette ); palette = dfb_core_create_palette( core ); if (!palette) return DFB_FUSION; palette->shmpool = dfb_core_shmpool( core ); if (size) { palette->entries = SHCALLOC( palette->shmpool, size, sizeof(DFBColor) ); if (!palette->entries) { fusion_object_destroy( &palette->object ); return D_OOSHM(); } palette->entries_yuv = SHCALLOC( palette->shmpool, size, sizeof(DFBColorYUV) ); if (!palette->entries_yuv) { SHFREE( palette->shmpool, palette->entries ); fusion_object_destroy( &palette->object ); return D_OOSHM(); } } palette->num_entries = size; /* reset cache */ palette->search_cache.index = -1; D_MAGIC_SET( palette, CorePalette ); /* activate object */ fusion_object_activate( &palette->object ); /* return the new palette */ *ret_palette = palette; D_DEBUG_AT( Core_Palette, " -> %p\n", palette ); return DFB_OK; }