DFBResult dfb_state_set_source_mask( CardState *state, CoreSurface *source_mask ) { D_MAGIC_ASSERT( state, CardState ); dfb_state_lock( state ); if (state->source_mask != source_mask) { if (source_mask && dfb_surface_ref( source_mask )) { D_WARN( "could not ref() source mask" ); dfb_state_unlock( state ); return DFB_DEAD; } if (state->source_mask) { D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_SOURCE_MASK ) ); dfb_surface_unref( state->source_mask ); } state->source_mask = source_mask; state->modified |= SMF_SOURCE_MASK; if (source_mask) { direct_serial_copy( &state->src_mask_serial, &source_mask->serial ); D_FLAGS_SET( state->flags, CSF_SOURCE_MASK ); } else D_FLAGS_CLEAR( state->flags, CSF_SOURCE_MASK ); } dfb_state_unlock( state ); return DFB_OK; }
void dfb_font_destroy( CoreFont *font ) { int i; D_MAGIC_ASSERT( font, CoreFont ); D_MAGIC_CLEAR( font ); pthread_mutex_lock( &font->lock ); dfb_state_set_destination( &font->state, NULL ); dfb_state_set_source( &font->state, NULL ); dfb_state_destroy( &font->state ); direct_tree_destroy( font->glyph_infos ); if (font->surfaces) { for (i = 0; i < font->rows; i++) dfb_surface_unref( font->surfaces[i] ); D_FREE( font->surfaces ); } pthread_mutex_unlock( &font->lock ); pthread_mutex_destroy( &font->lock ); D_FREE( font ); }
DFBResult dfb_state_set_source2( CardState *state, CoreSurface *source2 ) { D_MAGIC_ASSERT( state, CardState ); dfb_state_lock( state ); if (state->source2 != source2) { if (source2 && dfb_surface_ref( source2 )) { D_WARN( "could not ref() source2" ); dfb_state_unlock( state ); return DFB_DEAD; } if (state->source2) { D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_SOURCE2 ) ); dfb_surface_unref( state->source2 ); } state->source2 = source2; state->modified |= SMF_SOURCE2; if (source2) { direct_serial_copy( &state->src2_serial, &source2->serial ); D_FLAGS_SET( state->flags, CSF_SOURCE2 ); } else D_FLAGS_CLEAR( state->flags, CSF_SOURCE2 ); } dfb_state_unlock( state ); return DFB_OK; }
SurfacePeer::~SurfacePeer() { D_DEBUG_AT( DirectFB_Graphics, "Graphics::SurfacePeer::%s( %p, surface %p )\n", __FUNCTION__, this, surface ); if (surface) dfb_surface_unref( surface ); }
DFBResult IDirectFBSurface_Layer_Construct( IDirectFBSurface *thiz, IDirectFBSurface *parent, DFBRectangle *wanted, DFBRectangle *granted, CoreLayerRegion *region, DFBSurfaceCapabilities caps, CoreDFB *core ) { DFBResult ret; CoreSurface *surface; DIRECT_ALLOCATE_INTERFACE_DATA(thiz, IDirectFBSurface_Layer); D_DEBUG_AT( Surface, "%s( %p )\n", __FUNCTION__, thiz ); if (dfb_layer_region_ref( region )) return DFB_FUSION; ret = dfb_layer_region_get_surface( region, &surface ); if (ret) { dfb_layer_region_unref( region ); DIRECT_DEALLOCATE_INTERFACE(thiz); return ret; } ret = IDirectFBSurface_Construct( thiz, parent, wanted, granted, NULL, surface, surface->config.caps | caps, core ); if (ret) { dfb_surface_unref( surface ); dfb_layer_region_unref( region ); return ret; } dfb_surface_unref( surface ); data->region = region; thiz->Release = IDirectFBSurface_Layer_Release; thiz->Flip = IDirectFBSurface_Layer_Flip; thiz->GetSubSurface = IDirectFBSurface_Layer_GetSubSurface; return DFB_OK; }
static void IDirectFBImageProvider_WebP_Destruct( IDirectFBImageProvider *thiz ) { IDirectFBImageProvider_WebP_data *data = thiz->priv; if (data->decode_surface) { dfb_gfxcard_wait_serial( data->serial ); dfb_surface_unref( data->decode_surface ); } if (data->base.buffer) data->base.buffer->Release( data->base.buffer ); }
/* ------------------------------------------ */ static void IDirectFBVideoProvider_Swf_Destruct(IDirectFBVideoProvider *thiz ) { IDirectFBVideoProvider_Swf_data *data; data = (IDirectFBVideoProvider_Swf_data*)thiz->priv; thiz->Stop( thiz ); FlashClose(data->flashHandle); dfb_surface_unref( data->source ); DIRECT_DEALLOCATE_INTERFACE( thiz ); }
DFBResult dfb_state_set_source_2( CardState *state, CoreSurface *source, u32 flip_count ) { D_MAGIC_ASSERT( state, CardState ); dfb_state_lock( state ); if (state->source != source || state->source_flip_count != flip_count || !state->source_flip_count_used) { bool ref = true;//!fusion_config->secure_fusion || dfb_core_is_master( core_dfb ); if (source && ref && dfb_surface_ref( source )) { D_WARN( "could not ref() source" ); dfb_state_unlock( state ); return DFB_DEAD; } if (state->source) { D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_SOURCE ) ); if (ref) dfb_surface_unref( state->source ); } state->source = source; state->modified |= SMF_SOURCE; state->source_flip_count = flip_count; state->source_flip_count_used = true; if (source) { direct_serial_copy( &state->src_serial, &source->serial ); D_FLAGS_SET( state->flags, CSF_SOURCE ); } else D_FLAGS_CLEAR( state->flags, CSF_SOURCE ); } dfb_state_unlock( state ); return DFB_OK; }
DFBResult dfb_state_set_destination( CardState *state, CoreSurface *destination ) { D_MAGIC_ASSERT( state, CardState ); dfb_state_lock( state ); D_ASSUME( !(state->flags & CSF_DRAWING) ); if (state->destination != destination) { if (destination) { if (dfb_surface_ref( destination )) { D_WARN( "could not ref() destination" ); dfb_state_unlock( state ); return DFB_DEAD; } validate_clip( state, destination->config.size.w - 1, destination->config.size.h - 1, false ); } if (state->destination) { D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_DESTINATION ) ); dfb_surface_unref( state->destination ); } state->destination = destination; state->modified |= SMF_DESTINATION; if (destination) { direct_serial_copy( &state->dst_serial, &destination->serial ); D_FLAGS_SET( state->flags, CSF_DESTINATION ); } else D_FLAGS_CLEAR( state->flags, CSF_DESTINATION ); } dfb_state_unlock( state ); return DFB_OK; }
DFBResult ICore_Real::GetSurface( u32 surface_id, CoreSurface **ret_surface ) { DFBResult ret; CoreSurface *surface; char path[1000]; size_t path_length; D_DEBUG_AT( DirectFB_CoreDFB, "ICore_Real::%s( %u )\n", __FUNCTION__, surface_id ); D_MAGIC_ASSERT( obj, CoreDFB ); if (fusion_config->secure_fusion) { ret = (DFBResult) fusion_get_fusionee_path( dfb_core_world(core), Core_GetIdentity(), path, sizeof(path), &path_length ); if (ret) return ret; D_DEBUG_AT( DirectFB_CoreDFB, " -> '%s'\n", path ); } ret = dfb_core_get_surface( core, surface_id, &surface ); if (ret) return ret; if (fusion_config->secure_fusion) { ret = (DFBResult) fusion_object_has_access( &surface->object, path ); if (ret) { D_DEBUG_AT( DirectFB_CoreDFB, " -> NO ACCESS!\n" ); dfb_surface_unref( surface ); return ret; } // FIXME: access to this object needs to be given for other places like using as a blitting source surface->object.owner = Core_GetIdentity(); } *ret_surface = surface; return DFB_OK; }
static void IDirectFBVideoProvider_AviFile_Destruct( IDirectFBVideoProvider *thiz ) { IDirectFBVideoProvider_AviFile_data *data; data = (IDirectFBVideoProvider_AviFile_data*)thiz->priv; if (data->player->IsPlaying()) data->player->Stop(); delete data->player; if (data->destination) { data->destination->Release( data->destination ); data->destination = NULL; /* FIXME: remove listener */ } dfb_surface_unref( data->source ); DFB_DEALLOCATE_INTERFACE( thiz ); }
DFBResult dfb_state_set_source2( CardState *state, CoreSurface *source2 ) { D_MAGIC_ASSERT( state, CardState ); dfb_state_lock( state ); if (state->source2 != source2) { bool ref = true;//!fusion_config->secure_fusion || dfb_core_is_master( core_dfb ); if (source2 && ref && dfb_surface_ref( source2 )) { D_WARN( "could not ref() source2" ); dfb_state_unlock( state ); return DFB_DEAD; } if (state->source2) { D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_SOURCE2 ) ); if (ref) dfb_surface_unref( state->source2 ); } state->source2 = source2; state->modified |= SMF_SOURCE2; if (source2) { direct_serial_copy( &state->src2_serial, &source2->serial ); D_FLAGS_SET( state->flags, CSF_SOURCE2 ); } else D_FLAGS_CLEAR( state->flags, CSF_SOURCE2 ); } dfb_state_unlock( state ); return DFB_OK; }
static DFBResult IDirectFBImageProvider_WebP_RenderTo( IDirectFBImageProvider *thiz, IDirectFBSurface *destination, const DFBRectangle *dest_rect ) { DFBResult ret; DFBRegion clip; CoreSurface *dst_surface; CardState state; CoreSurfaceBufferLock lock; IDirectFBSurface_data *dst_data; DIRenderCallbackResult cb_result = DIRCR_OK; DFBRectangle src_rect; DFBRectangle rect; DIRECT_INTERFACE_GET_DATA( IDirectFBImageProvider_WebP ) if (!destination) return DFB_INVARG; dst_data = destination->priv; if (!dst_data || !dst_data->surface) return DFB_DESTROYED; dst_surface = dst_data->surface; if (dest_rect) { if (dest_rect->w < 1 || dest_rect->h < 1) return DFB_INVARG; rect = *dest_rect; rect.x += dst_data->area.wanted.x; rect.y += dst_data->area.wanted.y; } else { rect = dst_data->area.wanted; } dfb_region_from_rectangle( &clip, &dst_data->area.current ); if (!dfb_rectangle_region_intersects( &rect, &clip )) return DFB_OK; ret = dfb_surface_create_simple( data->base.core, data->width, data->height, data->pixelformat, DSCS_RGB, DSCAPS_NONE, CSTF_NONE, 0, NULL, &data->decode_surface ); if (ret) { D_ERROR( "Failed to create surface : '%s'\n", DirectResultString(ret) ); goto error; } ret = dfb_surface_lock_buffer( data->decode_surface, CSBR_BACK, CSAID_CPU, CSAF_WRITE, &lock ); if (ret) { D_ERROR( "Failed to lock the surface : '%s'\n", DirectResultString(ret) ); goto error; } ret = WebP_decode_image( data, &lock ); if (ret) { D_ERROR( "Failed to decode the image : '%s'\n", DirectResultString(ret) ); goto error; } dfb_surface_unlock_buffer( data->decode_surface, &lock ); dfb_state_init( &state, data->base.core ); state.modified |= SMF_CLIP; state.clip = DFB_REGION_INIT_FROM_RECTANGLE_VALS( rect.x, rect.y, rect.w, rect.h ); src_rect = (DFBRectangle){0, 0, data->width, data->height}; dfb_state_set_source( &state, data->decode_surface ); dfb_state_set_destination( &state, dst_surface ); dfb_gfxcard_batchstretchblit( &src_rect, &rect, 1, &state ); data->serial = &state.serial; dfb_state_set_source(&state, NULL); dfb_state_set_destination(&state, NULL); dfb_state_destroy(&state); if (data->base.render_callback) { DFBRectangle r = { 0, 0, data->width, data->height }; cb_result=data->base.render_callback( &r, data->base.render_callback_context ); } if (cb_result == DIRCR_OK) { data->base.buffer->Release( data->base.buffer ); data->base.buffer = NULL; } return DFB_OK; error: if (data->decode_surface && lock.pitch) dfb_surface_unlock_buffer( data->decode_surface, &lock ); dfb_surface_unref( data->decode_surface ); data->base.buffer->Release( data->base.buffer ); data->base.buffer = NULL; return ret; }
DFBResult dfb_window_create( CoreWindowStack *stack, int x, int y, int width, int height, DFBWindowCapabilities caps, DFBSurfaceCapabilities surface_caps, DFBSurfacePixelFormat pixelformat, CoreWindow **window ) { DFBResult ret; CoreSurface *surface; CoreSurfacePolicy surface_policy; CoreWindow *w; DisplayLayer *layer = dfb_layer_at( stack->layer_id ); CoreSurface *layer_surface = dfb_layer_surface( layer ); surface_caps &= DSCAPS_INTERLACED | DSCAPS_SEPERATED | DSCAPS_STATIC_ALLOC | DSCAPS_SYSTEMONLY | DSCAPS_VIDEOONLY; if (caps & DWCAPS_ALPHACHANNEL) { if (pixelformat == DSPF_UNKNOWN) pixelformat = DSPF_ARGB; else if (! DFB_PIXELFORMAT_HAS_ALPHA(pixelformat)) return DFB_INVARG; surface_policy = stack->wsp_alpha; } else { surface_policy = stack->wsp_opaque; if (pixelformat == DSPF_UNKNOWN) pixelformat = layer_surface->format; } if (surface_caps & DSCAPS_VIDEOONLY) surface_policy = CSP_VIDEOONLY; else if (surface_caps & DSCAPS_SYSTEMONLY) surface_policy = CSP_SYSTEMONLY; else if (layer_surface->back_buffer->policy == CSP_SYSTEMONLY) surface_policy = CSP_SYSTEMONLY; if (caps & DWCAPS_DOUBLEBUFFER) surface_caps |= DSCAPS_FLIPPING; /* Create the window object. */ w = (CoreWindow*) fusion_object_create( stack->pool ); /* Create the window's surface using the layer's palette. */ if (! (caps & DWCAPS_INPUTONLY)) { ret = dfb_surface_create( width, height, pixelformat, surface_policy, surface_caps, layer_surface->palette, &surface ); if (ret) { fusion_object_destroy( &w->object ); return ret; } dfb_surface_link( &w->surface, surface ); dfb_surface_unref( surface ); } w->id = new_window_id( stack ); w->x = x; w->y = y; w->width = width; w->height = height; w->caps = caps; w->opacity = 0; if (caps & DWCAPS_ALPHACHANNEL) w->options = DWOP_ALPHACHANNEL; w->stack = stack; w->events = DWET_ALL; *window = w; return DFB_OK;; }