static DFBResult set_region( CoreLayerRegion *region, CoreLayerRegionConfig *config, CoreLayerRegionConfigFlags flags, CoreSurface *surface ) { CoreLayer *layer; DisplayLayerFuncs *funcs; D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); D_ASSERT( config != NULL ); D_ASSERT( config->buffermode != DLBM_WINDOWS ); 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->funcs != NULL ); D_ASSERT( layer->funcs->SetRegion != NULL ); funcs = layer->funcs; /* Setup hardware. */ return funcs->SetRegion( layer, layer->driver_data, layer->layer_data, region->region_data, config, flags, surface, surface ? surface->palette : NULL ); }
static void handle_expose( const XExposeEvent *expose ) { CoreLayer *layer = 0; const DisplayLayerFuncs *funcs = 0; CoreLayerContext *context; int i; /* find the correct layer */ for( i=0; i<dfb_layer_num(); i++ ) { X11LayerData *lds; layer = dfb_layer_at( i ); lds = (X11LayerData*)(layer->layer_data); if( lds->xw && (lds->xw->window == expose->window) ) break; } /* layer not found? */ if( i==dfb_layer_num() ) return; funcs = layer->funcs; D_ASSERT( funcs != NULL ); D_ASSERT( funcs->UpdateRegion != NULL ); /* Get the currently active context. */ if (dfb_layer_get_active_context( layer, &context ) == DFB_OK) { CoreLayerRegion *region; /* Get the first region. */ if (dfb_layer_context_get_primary_region( context, false, ®ion ) == DFB_OK) { /* Lock the region to avoid tearing due to concurrent updates. */ dfb_layer_region_lock( region ); /* Get the surface of the region. */ if (region->surface && region->left_buffer_lock.buffer) { DFBRegion update = { expose->x, expose->y, expose->x + expose->width - 1, expose->y + expose->height - 1 }; funcs->UpdateRegion( layer, layer->driver_data, layer->layer_data, region->region_data, region->surface, &update, ®ion->left_buffer_lock, NULL, NULL ); } /* Unlock the region. */ dfb_layer_region_unlock( region ); /* Release the region. */ dfb_layer_region_unref( region ); } /* Release the context. */ dfb_layer_context_unref( context ); } }
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 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 ); }
void uc_ovl_setup_fifo(UcOverlayData* ucovl, int scrwidth) { u8* mclk_save = ucovl->mclk_save; if (!iopl(3)) { if (scrwidth <= 1024) { // Disable if (ucovl->extfifo_on) { dfb_layer_wait_vsync(dfb_layer_at(DLID_PRIMARY)); outb(0x16, 0x3c4); outb(mclk_save[0], 0x3c5); outb(0x17, 0x3c4); outb(mclk_save[1], 0x3c5); outb(0x18, 0x3c4); outb(mclk_save[2], 0x3c5); ucovl->extfifo_on = false; } } else { // Enable if (!ucovl->extfifo_on) { dfb_layer_wait_vsync(dfb_layer_at(DLID_PRIMARY)); // Save current setting outb(0x16, 0x3c4); mclk_save[0] = inb(0x3c5); outb(0x17, 0x3c4); mclk_save[1] = inb(0x3c5); outb(0x18, 0x3c4); mclk_save[2] = inb(0x3c5); // Enable extended FIFO outb(0x17, 0x3c4); outb(0x2f, 0x3c5); outb(0x16, 0x3c4); outb((mclk_save[0] & 0xf0) | 0x14, 0x3c5); outb(0x18, 0x3c4); outb(0x56, 0x3c5); ucovl->extfifo_on = true; } } } else { printf("cle266: could set io perissons\n"); } ucovl->scrwidth = scrwidth; }
DFBResult dfb_layer_region_create( CoreLayerContext *context, CoreLayerRegion **ret_region ) { CoreLayer *layer; CoreLayerRegion *region; D_ASSERT( context != NULL ); D_ASSERT( ret_region != NULL ); layer = dfb_layer_at( context->layer_id ); /* Create the object. */ region = dfb_core_create_layer_region( layer->core ); if (!region) return DFB_FUSION; /* Link the context into the structure. */ if (dfb_layer_context_link( ®ion->context, context )) { fusion_object_destroy( ®ion->object ); return DFB_FUSION; } /* Initialize the lock. */ if (fusion_skirmish_init( ®ion->lock, "Layer Region", dfb_core_world(layer->core) )) { dfb_layer_context_unlink( ®ion->context ); fusion_object_destroy( ®ion->object ); return DFB_FUSION; } /* Change global reaction lock. */ fusion_object_set_lock( ®ion->object, ®ion->lock ); region->state = CLRSF_FROZEN; /* Activate the object. */ fusion_object_activate( ®ion->object ); /* Add the region to the context. */ dfb_layer_context_add_region( context, region ); /* Return the new region. */ *ret_region = region; return DFB_OK; }
static void repaint_stack( CoreWindowStack *stack, DFBRegion *region, DFBSurfaceFlipFlags flags ) { DisplayLayer *layer = dfb_layer_at( stack->layer_id ); CoreSurface *surface = dfb_layer_surface( layer ); CardState *state = dfb_layer_state( layer ); if (!dfb_region_intersect( region, 0, 0, surface->width - 1, surface->height - 1 )) return; if (dfb_layer_lease( layer )) return; state->clip = *region; state->modified |= SMF_CLIP; update_region( stack, state, stack->num_windows - 1, region->x1, region->y1, region->x2, region->y2 ); if (surface->caps & DSCAPS_FLIPPING) { if (region->x1 == 0 && region->y1 == 0 && region->x2 == surface->width - 1 && region->y2 == surface->height - 1 && 0) { dfb_layer_flip_buffers( layer, flags ); } else { DFBRectangle rect = { region->x1, region->y1, region->x2 - region->x1 + 1, region->y2 - region->y1 + 1 }; if (flags & DSFLIP_WAITFORSYNC) dfb_fbdev_wait_vsync(); dfb_back_to_front_copy( surface, &rect ); } } dfb_layer_release( layer, false ); }
/* * listen to the layer's surface */ ReactionResult _dfb_layer_region_surface_listener( const void *msg_data, void *ctx ) { CoreSurfaceNotificationFlags flags; CoreSurface *surface; CoreLayer *layer; CoreLayerShared *shared; DisplayLayerFuncs *funcs; const CoreSurfaceNotification *notification = msg_data; CoreLayerRegion *region = ctx; D_ASSERT( notification != NULL ); D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); D_DEBUG_AT( Core_Layers, "_dfb_layer_region_surface_listener( %p, %p ) <- 0x%08x\n", notification, region, notification->flags ); D_ASSERT( notification->surface != NULL ); D_ASSUME( notification->surface == region->surface ); if (notification->surface != region->surface) return RS_OK; layer = dfb_layer_at( region->context->layer_id ); D_ASSERT( layer != NULL ); D_ASSERT( layer->funcs != NULL ); D_ASSERT( layer->funcs->SetRegion != NULL ); D_ASSERT( layer->shared != NULL ); funcs = layer->funcs; shared = layer->shared; flags = notification->flags; surface = notification->surface; if (flags & CSNF_DESTROY) { D_WARN( "layer region surface destroyed" ); region->surface = NULL; return RS_REMOVE; } if (dfb_layer_region_lock( region )) return RS_OK; if (D_FLAGS_ARE_SET( region->state, CLRSF_REALIZED | CLRSF_CONFIGURED )) { if (D_FLAGS_IS_SET( flags, CSNF_PALETTE_CHANGE | CSNF_PALETTE_UPDATE )) { if (surface->palette) funcs->SetRegion( layer, layer->driver_data, layer->layer_data, region->region_data, ®ion->config, CLRCF_PALETTE, surface, surface->palette ); } if ((flags & CSNF_FIELD) && funcs->SetInputField) funcs->SetInputField( layer, layer->driver_data, layer->layer_data, region->region_data, surface->field ); if ((flags & CSNF_ALPHA_RAMP) && (shared->description.caps & DLCAPS_ALPHA_RAMP)) { region->config.alpha_ramp[0] = surface->alpha_ramp[0]; region->config.alpha_ramp[1] = surface->alpha_ramp[1]; region->config.alpha_ramp[2] = surface->alpha_ramp[2]; region->config.alpha_ramp[3] = surface->alpha_ramp[3]; funcs->SetRegion( layer, layer->driver_data, layer->layer_data, region->region_data, ®ion->config, CLRCF_ALPHA_RAMP, surface, surface->palette ); } } dfb_layer_region_unlock( region ); return RS_OK; }
DFBResult dfb_layer_region_set_configuration( CoreLayerRegion *region, CoreLayerRegionConfig *config, CoreLayerRegionConfigFlags flags ) { DFBResult ret; CoreLayer *layer; DisplayLayerFuncs *funcs; CoreLayerRegionConfig new_config; D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); D_ASSERT( config != NULL ); D_ASSERT( config->buffermode != DLBM_WINDOWS ); D_ASSERT( (flags == CLRCF_ALL) || (region->state & CLRSF_CONFIGURED) ); D_ASSUME( flags != CLRCF_NONE ); D_ASSUME( ! (flags & ~CLRCF_ALL) ); layer = dfb_layer_at( region->context->layer_id ); D_ASSERT( layer != NULL ); D_ASSERT( layer->funcs != NULL ); D_ASSERT( layer->funcs->TestRegion != NULL ); funcs = layer->funcs; /* Lock the region. */ if (dfb_layer_region_lock( region )) return DFB_FUSION; /* Full configuration supplied? */ if (flags == CLRCF_ALL) { new_config = *config; } else { /* Use the current configuration. */ new_config = region->config; /* Update each modified entry. */ if (flags & CLRCF_WIDTH) new_config.width = config->width; if (flags & CLRCF_HEIGHT) new_config.height = config->height; if (flags & CLRCF_FORMAT) new_config.format = config->format; if (flags & CLRCF_SURFACE_CAPS) new_config.surface_caps = config->surface_caps; if (flags & CLRCF_BUFFERMODE) new_config.buffermode = config->buffermode; if (flags & CLRCF_OPTIONS) new_config.options = config->options; if (flags & CLRCF_SOURCE_ID) new_config.source_id = config->source_id; if (flags & CLRCF_SOURCE) new_config.source = config->source; if (flags & CLRCF_DEST) new_config.dest = config->dest; if (flags & CLRCF_OPACITY) new_config.opacity = config->opacity; if (flags & CLRCF_ALPHA_RAMP) { new_config.alpha_ramp[0] = config->alpha_ramp[0]; new_config.alpha_ramp[1] = config->alpha_ramp[1]; new_config.alpha_ramp[2] = config->alpha_ramp[2]; new_config.alpha_ramp[3] = config->alpha_ramp[3]; } if (flags & CLRCF_SRCKEY) new_config.src_key = config->src_key; if (flags & CLRCF_DSTKEY) new_config.dst_key = config->dst_key; if (flags & CLRCF_PARITY) new_config.parity = config->parity; } /* Check if the new configuration is supported. */ ret = funcs->TestRegion( layer, layer->driver_data, layer->layer_data, &new_config, NULL ); if (ret) { dfb_layer_region_unlock( region ); return ret; } /* Propagate new configuration to the driver if the region is realized. */ if (D_FLAGS_IS_SET( region->state, CLRSF_REALIZED )) { ret = set_region( region, &new_config, flags, region->surface ); if (ret) { dfb_layer_region_unlock( region ); return ret; } } /* Update the region's current configuration. */ region->config = new_config; /* Update the region's state. */ D_FLAGS_SET( region->state, CLRSF_CONFIGURED ); /* Unlock the region. */ dfb_layer_region_unlock( region ); return DFB_OK; }
DFBResult dfb_layer_region_flip_update( CoreLayerRegion *region, const DFBRegion *update, DFBSurfaceFlipFlags flags ) { DFBResult ret = DFB_OK; CoreLayer *layer; CoreLayerContext *context; CoreSurface *surface; SurfaceBuffer *buffer; DisplayLayerFuncs *funcs; if (update) D_DEBUG_AT( Core_Layers, "dfb_layer_region_flip_update( %p, %p, 0x%08x ) <- [%d, %d - %dx%d]\n", region, update, flags, DFB_RECTANGLE_VALS_FROM_REGION( update ) ); else D_DEBUG_AT( Core_Layers, "dfb_layer_region_flip_update( %p, %p, 0x%08x )\n", region, update, flags ); D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); /* Lock the region. */ if (dfb_layer_region_lock( region )) return DFB_FUSION; D_ASSUME( region->surface != NULL ); /* Check for NULL surface. */ if (!region->surface) { D_DEBUG_AT( Core_Layers, " -> No surface => no update!\n" ); dfb_layer_region_unlock( region ); return DFB_UNSUPPORTED; } context = region->context; surface = region->surface; buffer = surface->back_buffer; layer = dfb_layer_at( context->layer_id ); D_ASSERT( layer->funcs != NULL ); funcs = layer->funcs; /* Depending on the buffer mode... */ switch (region->config.buffermode) { case DLBM_TRIPLE: case DLBM_BACKVIDEO: /* Check if simply swapping the buffers is possible... */ if (!(flags & DSFLIP_BLIT) && (!update || (update->x1 == 0 && update->y1 == 0 && update->x2 == surface->width - 1 && update->y2 == surface->height - 1))) { D_DEBUG_AT( Core_Layers, " -> Going to swap buffers...\n" ); /* Use the driver's routine if the region is realized. */ if (D_FLAGS_IS_SET( region->state, CLRSF_REALIZED )) { D_ASSUME( funcs->FlipRegion != NULL ); D_DEBUG_AT( Core_Layers, " -> Waiting for pending writes...\n" ); if (buffer->video.access & VAF_HARDWARE_WRITE) { dfb_gfxcard_wait_serial( &buffer->video.serial ); buffer->video.access &= ~VAF_HARDWARE_WRITE; } D_DEBUG_AT( Core_Layers, " -> Flipping region using driver...\n" ); if (funcs->FlipRegion) ret = funcs->FlipRegion( layer, layer->driver_data, layer->layer_data, region->region_data, surface, flags ); } else { D_DEBUG_AT( Core_Layers, " -> Flipping region not using driver...\n" ); /* Just do the hardware independent work. */ dfb_surface_flip_buffers( surface, false ); } break; } /* fall through */ case DLBM_BACKSYSTEM: D_DEBUG_AT( Core_Layers, " -> Going to copy portion...\n" ); if ((flags & DSFLIP_WAITFORSYNC) == DSFLIP_WAITFORSYNC) { D_DEBUG_AT( Core_Layers, " -> Waiting for VSync...\n" ); dfb_layer_wait_vsync( layer ); } D_DEBUG_AT( Core_Layers, " -> Copying content from back to front buffer...\n" ); /* ...or copy updated contents from back to front buffer. */ dfb_back_to_front_copy( surface, update ); if ((flags & DSFLIP_WAITFORSYNC) == DSFLIP_WAIT) { D_DEBUG_AT( Core_Layers, " -> Waiting for VSync...\n" ); dfb_layer_wait_vsync( layer ); } /* fall through */ case DLBM_FRONTONLY: /* Tell the driver about the update if the region is realized. */ if (funcs->UpdateRegion && D_FLAGS_IS_SET( region->state, CLRSF_REALIZED )) { D_DEBUG_AT( Core_Layers, " -> Notifying driver about updated content...\n" ); ret = funcs->UpdateRegion( layer, layer->driver_data, layer->layer_data, region->region_data, surface, update ); } break; default: D_BUG("unknown buffer mode"); ret = DFB_BUG; } D_DEBUG_AT( Core_Layers, " -> done.\n" ); /* Unlock the region. */ dfb_layer_region_unlock( region ); return ret; }
static ReactionResult stack_inputdevice_react( const void *msg_data, void *ctx ) { const DFBInputEvent *evt = (DFBInputEvent*)msg_data; DFBWindowEvent we; CoreWindow *window = NULL; CoreWindowStack *stack = (CoreWindowStack*)ctx; DisplayLayer *layer = dfb_layer_at( stack->layer_id ); /* FIXME: this is a bad check for exclusive access */ if (dfb_layer_lease( layer ) ) return RS_OK; dfb_layer_release( layer, false ); if (stack->wm_hack) { switch (evt->type) { case DIET_KEYRELEASE: switch (evt->key_symbol) { case DIKS_CAPS_LOCK: stack->wm_hack = 0; stack_lock( stack ); handle_enter_leave_focus( stack ); stack_unlock( stack ); break; case DIKS_CONTROL: stack->wm_hack = 1; return RS_OK; default: ; } break; case DIET_KEYPRESS: switch (DFB_LOWER_CASE(evt->key_symbol)) { case DIKS_CONTROL: stack->wm_hack = 2; return RS_OK; case DIKS_SMALL_C: if (stack->entered_window) { DFBWindowEvent evt; evt.type = DWET_CLOSE; dfb_window_dispatch( stack->entered_window, &evt ); } return RS_OK; case DIKS_SMALL_D: { CoreWindow *window = stack->entered_window; if (window && !(window->options & DWOP_INDESTRUCTIBLE)) { dfb_window_deinit( window ); dfb_window_destroy( window, true ); } return RS_OK; } default: ; } break; case DIET_BUTTONRELEASE: return RS_OK; case DIET_BUTTONPRESS: if (stack->entered_window && !(stack->entered_window->options & DWOP_KEEP_STACKING)) dfb_window_raisetotop( stack->entered_window ); return RS_OK; default: ; } } switch (evt->type) { case DIET_KEYPRESS: if (evt->key_id == DIKI_CAPS_LOCK) stack->wm_hack = 1; /* fall through */ case DIET_KEYRELEASE: stack_lock( stack ); window = (stack->keyboard_window ? stack->keyboard_window : stack->focused_window); if (window) { we.type = (evt->type == DIET_KEYPRESS) ? DWET_KEYDOWN : DWET_KEYUP; we.key_code = evt->key_code; we.key_id = evt->key_id; we.key_symbol = evt->key_symbol; we.modifiers = evt->modifiers; /* FIXME: handle mult. devices */ we.locks = evt->locks; /* FIXME: handle mult. devices */ dfb_window_dispatch( window, &we ); } stack_unlock( stack ); break; case DIET_BUTTONPRESS: case DIET_BUTTONRELEASE: if (!stack->cursor.enabled) break; stack_lock( stack ); window = (stack->pointer_window ? stack->pointer_window : stack->entered_window); if (window) { we.type = (evt->type == DIET_BUTTONPRESS) ? DWET_BUTTONDOWN : DWET_BUTTONUP; we.button = evt->button; we.buttons = evt->buttons; /* FIXME: handle mult. devices */ we.cx = stack->cursor.x; we.cy = stack->cursor.y; we.x = we.cx - window->x; we.y = we.cy - window->y; dfb_window_dispatch( window, &we ); } stack_unlock( stack ); break; case DIET_AXISMOTION: if (evt->flags & DIEF_AXISREL) { int rel = evt->axisrel; /* handle cursor acceleration */ if (rel > stack->cursor.threshold) rel += (rel - stack->cursor.threshold) * stack->cursor.numerator / stack->cursor.denominator; else if (rel < -stack->cursor.threshold) rel += (rel + stack->cursor.threshold) * stack->cursor.numerator / stack->cursor.denominator; switch (evt->axis) { case DIAI_X: dfb_windowstack_handle_motion( stack, rel, 0 ); break; case DIAI_Y: dfb_windowstack_handle_motion( stack, 0, rel ); break; case DIAI_Z: handle_wheel( stack, - evt->axisrel ); break; default: return RS_OK; } } else if (evt->flags & DIEF_AXISABS) { switch (evt->axis) { case DIAI_X: dfb_windowstack_handle_motion( stack, evt->axisabs - stack->cursor.x, 0 ); break; case DIAI_Y: dfb_windowstack_handle_motion( stack, 0, evt->axisabs - stack->cursor.y); break; default: return RS_OK; } } break; default: break; } return RS_OK; }
DFBResult dfb_layer_region_flip_update( CoreLayerRegion *region, const DFBRegion *update, DFBSurfaceFlipFlags flags ) { DFBResult ret = DFB_OK; DFBRegion rotated; CoreLayer *layer; CoreLayerContext *context; CoreSurface *surface; const DisplayLayerFuncs *funcs; if (update) D_DEBUG_AT( Core_Layers, "dfb_layer_region_flip_update( %p, %p, 0x%08x ) <- [%d, %d - %dx%d]\n", region, update, flags, DFB_RECTANGLE_VALS_FROM_REGION( update ) ); else D_DEBUG_AT( Core_Layers, "dfb_layer_region_flip_update( %p, %p, 0x%08x )\n", region, update, flags ); D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); /* Lock the region. */ if (dfb_layer_region_lock( region )) return DFB_FUSION; D_ASSUME( region->surface != NULL ); /* Check for NULL surface. */ if (!region->surface) { D_DEBUG_AT( Core_Layers, " -> No surface => no update!\n" ); dfb_layer_region_unlock( region ); return DFB_UNSUPPORTED; } context = region->context; surface = region->surface; layer = dfb_layer_at( context->layer_id ); D_ASSERT( layer->funcs != NULL ); funcs = layer->funcs; /* Unfreeze region? */ if (D_FLAGS_IS_SET( region->state, CLRSF_FROZEN )) { D_FLAGS_CLEAR( region->state, CLRSF_FROZEN ); if (D_FLAGS_IS_SET( region->state, CLRSF_REALIZED )) { ret = set_region( region, ®ion->config, CLRCF_ALL, surface ); if (ret) D_DERROR( ret, "Core/LayerRegion: set_region() in dfb_layer_region_flip_update() failed!\n" ); } else if (D_FLAGS_ARE_SET( region->state, CLRSF_ENABLED | CLRSF_ACTIVE )) { ret = realize_region( region ); if (ret) D_DERROR( ret, "Core/LayerRegion: realize_region() in dfb_layer_region_flip_update() failed!\n" ); } if (ret) { dfb_layer_region_unlock( region ); return ret; } } /* Depending on the buffer mode... */ switch (region->config.buffermode) { case DLBM_TRIPLE: case DLBM_BACKVIDEO: /* Check if simply swapping the buffers is possible... */ if (!(flags & DSFLIP_BLIT) && !surface->rotation && (!update || (update->x1 == 0 && update->y1 == 0 && update->x2 == surface->config.size.w - 1 && update->y2 == surface->config.size.h - 1))) { D_DEBUG_AT( Core_Layers, " -> Going to swap buffers...\n" ); /* Use the driver's routine if the region is realized. */ if (D_FLAGS_IS_SET( region->state, CLRSF_REALIZED )) { D_ASSUME( funcs->FlipRegion != NULL ); ret = region_buffer_lock( region, surface, CSBR_BACK ); if (ret) { dfb_layer_region_unlock( region ); return ret; } D_DEBUG_AT( Core_Layers, " -> Flipping region using driver...\n" ); if (funcs->FlipRegion) ret = funcs->FlipRegion( layer, layer->driver_data, layer->layer_data, region->region_data, surface, flags, ®ion->surface_lock ); dfb_surface_unlock( surface ); } else { D_DEBUG_AT( Core_Layers, " -> Flipping region not using driver...\n" ); /* Just do the hardware independent work. */ dfb_surface_lock( surface ); dfb_surface_flip( surface, false ); dfb_surface_unlock( surface ); } break; } /* fall through */ case DLBM_BACKSYSTEM: D_DEBUG_AT( Core_Layers, " -> Going to copy portion...\n" ); if ((flags & DSFLIP_WAITFORSYNC) == DSFLIP_WAITFORSYNC) { D_DEBUG_AT( Core_Layers, " -> Waiting for VSync...\n" ); dfb_layer_wait_vsync( layer ); } D_DEBUG_AT( Core_Layers, " -> Copying content from back to front buffer...\n" ); /* ...or copy updated contents from back to front buffer. */ dfb_back_to_front_copy_rotation( surface, update, surface->rotation ); if ((flags & DSFLIP_WAITFORSYNC) == DSFLIP_WAIT) { D_DEBUG_AT( Core_Layers, " -> Waiting for VSync...\n" ); dfb_layer_wait_vsync( layer ); } /* fall through */ case DLBM_FRONTONLY: /* Tell the driver about the update if the region is realized. */ if (funcs->UpdateRegion && D_FLAGS_IS_SET( region->state, CLRSF_REALIZED )) { if (surface) { CoreSurfaceAllocation *allocation; allocation = region->surface_lock.allocation; D_ASSERT( allocation != NULL ); /* If hardware has written or is writing... */ if (allocation->accessed[CSAID_GPU] & CSAF_WRITE) { D_DEBUG_AT( Core_Layers, " -> Waiting for pending writes...\n" ); /* ...wait for the operation to finish. */ if (!(flags & DSFLIP_PIPELINE)) dfb_gfxcard_sync(); /* TODO: wait for serial instead */ allocation->accessed[CSAID_GPU] &= ~CSAF_WRITE; } dfb_surface_lock( surface ); dfb_surface_allocation_update( allocation, CSAF_READ ); dfb_surface_unlock( surface ); } D_DEBUG_AT( Core_Layers, " -> Notifying driver about updated content...\n" ); dfb_region_from_rotated( &rotated, update, &surface->config.size, surface->rotation ); ret = funcs->UpdateRegion( layer, layer->driver_data, layer->layer_data, region->region_data, surface, &rotated, ®ion->surface_lock ); } break; default: D_BUG("unknown buffer mode"); ret = DFB_BUG; } D_DEBUG_AT( Core_Layers, " -> done.\n" ); /* Unlock the region. */ dfb_layer_region_unlock( region ); return ret; }
static DFBResult set_region( CoreLayerRegion *region, CoreLayerRegionConfig *config, CoreLayerRegionConfigFlags flags, CoreSurface *surface ) { DFBResult ret = DFB_OK; CoreLayer *layer; const DisplayLayerFuncs *funcs; D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); D_ASSERT( config != NULL ); D_ASSERT( config->buffermode != DLBM_WINDOWS ); 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->funcs != NULL ); D_ASSERT( layer->funcs->SetRegion != NULL ); if (region->state & CLRSF_FROZEN) return DFB_OK; funcs = layer->funcs; if (surface) { if (flags & (CLRCF_SURFACE | CLRCF_WIDTH | CLRCF_HEIGHT | CLRCF_FORMAT)) { if (region->surface_lock.buffer) { CoreSurfaceBuffer *buffer = region->surface_lock.buffer; D_MAGIC_ASSERT( buffer, CoreSurfaceBuffer ); if (surface == buffer->surface) { if (dfb_surface_lock( surface )) return DFB_FUSION; dfb_surface_buffer_unlock( ®ion->surface_lock ); buffer = dfb_surface_get_buffer( surface, CSBR_FRONT ); D_MAGIC_ASSERT( buffer, CoreSurfaceBuffer ); ret = dfb_surface_buffer_lock( buffer, CSAF_CPU_READ | CSAF_GPU_READ, ®ion->surface_lock ); dfb_surface_unlock( surface ); } else { dfb_surface_unlock_buffer( buffer->surface, ®ion->surface_lock ); ret = dfb_surface_lock_buffer( surface, CSBR_FRONT, CSAF_CPU_READ | CSAF_GPU_READ, ®ion->surface_lock ); } } else ret = dfb_surface_lock_buffer( surface, CSBR_FRONT, CSAF_CPU_READ | CSAF_GPU_READ, ®ion->surface_lock ); } if (ret) { D_DERROR( ret, "Core/LayerRegion: Could not lock region surface for SetRegion()!\n" ); return ret; } D_ASSERT( region->surface_lock.buffer != NULL ); } else if (region->surface_lock.buffer) { D_MAGIC_ASSERT( region->surface_lock.buffer, CoreSurfaceBuffer ); dfb_surface_unlock_buffer( region->surface_lock.buffer->surface, ®ion->surface_lock ); } /* Setup hardware. */ return funcs->SetRegion( layer, layer->driver_data, layer->layer_data, region->region_data, config, flags, surface, surface ? surface->palette : NULL, ®ion->surface_lock ); }
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;; }
static DFBResult realize_region( CoreLayerRegion *region ) { DFBResult ret; CoreLayer *layer; CoreLayerShared *shared; DisplayLayerFuncs *funcs; D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); D_ASSERT( D_FLAGS_IS_SET( region->state, CLRSF_CONFIGURED ) ); 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 ) ); /* Allocate the driver's region data. */ if (funcs->RegionDataSize) { int size = funcs->RegionDataSize(); if (size > 0) { region->region_data = SHCALLOC( 1, size ); if (!region->region_data) return D_OOSHM(); } } D_DEBUG_AT( Core_Layers, "Adding region (%d, %d - %dx%d) to '%s'.\n", DFB_RECTANGLE_VALS( ®ion->config.dest ), shared->description.name ); /* Add the region to the driver. */ if (funcs->AddRegion) { ret = funcs->AddRegion( layer, layer->driver_data, layer->layer_data, region->region_data, ®ion->config ); if (ret) { D_DERROR( ret, "Core/Layers: Could not add region!\n" ); if (region->region_data) { SHFREE( region->region_data ); region->region_data = NULL; } return ret; } } /* Add the region to the 'added' list. */ fusion_vector_add( &shared->added_regions, region ); /* Update the region's state. */ D_FLAGS_SET( region->state, CLRSF_REALIZED ); /* Initially setup hardware. */ ret = set_region( region, ®ion->config, CLRCF_ALL, region->surface ); if (ret) { unrealize_region( region ); return ret; } return DFB_OK; }
/* HACK: implementation dumped in here for now, will move into context */ static DFBResult wm_update_cursor( CoreWindowStack *stack, void *wm_data, void *stack_data, CoreCursorUpdateFlags flags ) { DFBResult ret; DFBRegion old_region; WMData *wmdata = wm_data; StackData *data = stack_data; bool restored = false; CoreLayer *layer; CoreLayerRegion *region; CardState *state; CoreSurface *surface; UniqueContext *context; D_ASSERT( stack != NULL ); D_ASSERT( stack->context != NULL ); D_ASSERT( wm_data != NULL ); D_ASSERT( stack_data != NULL ); D_MAGIC_ASSERT( data, StackData ); context = data->context; D_MAGIC_ASSERT( context, UniqueContext ); /* Optimize case of invisible cursor moving. */ if (!(flags & ~(CCUF_POSITION | CCUF_SHAPE)) && (!stack->cursor.opacity || !stack->cursor.enabled)) { context->cursor_bs_valid = false; return DFB_OK; } layer = dfb_layer_at( context->layer_id ); state = &layer->state; region = context->region; surface = context->surface; D_ASSERT( region != NULL ); D_ASSERT( surface != NULL ); if (flags & CCUF_ENABLE) { CoreSurface *cursor_bs; DFBSurfaceCapabilities caps = DSCAPS_NONE; dfb_surface_caps_apply_policy( stack->cursor.policy, &caps ); D_ASSERT( context->cursor_bs == NULL ); /* Create the cursor backing store surface. */ ret = dfb_surface_create_simple( wmdata->core, stack->cursor.size.w, stack->cursor.size.h, region->config.format, region->config.colorspace, caps, CSTF_SHARED | CSTF_CURSOR, 0, /* FIXME: no shared cursor objects, no cursor id */ NULL, &cursor_bs ); if (ret) { D_ERROR( "WM/Default: Failed creating backing store for cursor!\n" ); return ret; } ret = dfb_surface_globalize( cursor_bs ); D_ASSERT( ret == DFB_OK ); /* Ensure valid back buffer for now. * FIXME: Keep a flag to know when back/front have been swapped and need a sync. */ switch (region->config.buffermode) { case DLBM_BACKVIDEO: case DLBM_TRIPLE: dfb_gfx_copy( surface, surface, NULL ); break; default: break; } context->cursor_bs = cursor_bs; } else { D_ASSERT( context->cursor_bs != NULL ); /* restore region under cursor */ if (context->cursor_drawn) { DFBRectangle rect = { 0, 0, context->cursor_region.x2 - context->cursor_region.x1 + 1, context->cursor_region.y2 - context->cursor_region.y1 + 1 }; D_ASSERT( stack->cursor.opacity || (flags & CCUF_OPACITY) ); D_ASSERT( context->cursor_bs_valid ); dfb_gfx_copy_to( context->cursor_bs, surface, &rect, context->cursor_region.x1, context->cursor_region.y1, false ); context->cursor_drawn = false; old_region = context->cursor_region; restored = true; } if (flags & CCUF_SIZE) { ret = dfb_surface_reformat( context->cursor_bs, stack->cursor.size.w, stack->cursor.size.h, context->cursor_bs->config.format ); if (ret) { D_ERROR( "WM/Default: Failed resizing backing store for cursor!\n" ); return ret; } } } if (flags & (CCUF_ENABLE | CCUF_POSITION | CCUF_SIZE | CCUF_OPACITY)) { context->cursor_bs_valid = false; context->cursor_region.x1 = stack->cursor.x - stack->cursor.hot.x; context->cursor_region.y1 = stack->cursor.y - stack->cursor.hot.y; context->cursor_region.x2 = context->cursor_region.x1 + stack->cursor.size.w - 1; context->cursor_region.y2 = context->cursor_region.y1 + stack->cursor.size.h - 1; if (!dfb_region_intersect( &context->cursor_region, 0, 0, stack->width - 1, stack->height - 1 )) { D_BUG( "invalid cursor region" ); return DFB_BUG; } } D_ASSERT( context->cursor_bs != NULL ); if (flags & CCUF_DISABLE) { dfb_surface_unlink( &context->cursor_bs ); } else if (stack->cursor.opacity) { /* backup region under cursor */ if (!context->cursor_bs_valid) { DFBRectangle rect = DFB_RECTANGLE_INIT_FROM_REGION( &context->cursor_region ); D_ASSERT( !context->cursor_drawn ); /* FIXME: this requires using blitted flipping all the time, but fixing it seems impossible, for now DSFLIP_BLIT is forced in repaint_stack() when the cursor is enabled. */ dfb_gfx_copy_to( surface, context->cursor_bs, &rect, 0, 0, true ); context->cursor_bs_valid = true; } /* Set destination. */ state->destination = surface; state->modified |= SMF_DESTINATION; /* Set clipping region. */ dfb_state_set_clip( state, &context->cursor_region ); /* draw cursor */ unique_draw_cursor( stack, context, state, &context->cursor_region ); /* Reset destination. */ state->destination = NULL; state->modified |= SMF_DESTINATION; context->cursor_drawn = true; if (restored) { if (dfb_region_region_intersects( &old_region, &context->cursor_region )) dfb_region_region_union( &old_region, &context->cursor_region ); else dfb_layer_region_flip_update( region, &context->cursor_region, DSFLIP_BLIT ); dfb_layer_region_flip_update( region, &old_region, DSFLIP_BLIT ); } else dfb_layer_region_flip_update( region, &context->cursor_region, DSFLIP_BLIT ); } else if (restored) dfb_layer_region_flip_update( region, &old_region, DSFLIP_BLIT ); return DFB_OK; }
static DFBResult set_region( CoreLayerRegion *region, CoreLayerRegionConfig *config, CoreLayerRegionConfigFlags flags, CoreSurface *surface ) { DFBResult ret; CoreLayer *layer; CoreLayerShared *shared; const DisplayLayerFuncs *funcs; D_DEBUG_AT( Core_Layers, "%s( %p, %p, 0x%08x, %p )\n", __FUNCTION__, region, config, flags, surface ); DFB_CORE_LAYER_REGION_CONFIG_DEBUG_AT( Core_Layers, config ); D_DEBUG_AT( Core_Layers, " -> state 0x%08x\n", region->state ); D_ASSERT( region != NULL ); D_ASSERT( region->context != NULL ); D_ASSERT( config != NULL ); D_ASSERT( config->buffermode != DLBM_WINDOWS ); 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 ); D_ASSERT( layer->funcs->SetRegion != NULL ); if (region->state & CLRSF_FROZEN) { D_DEBUG_AT( Core_Layers, " -> FROZEN!\n" ); return DFB_OK; } shared = layer->shared; funcs = layer->funcs; if (surface) { if (flags & (CLRCF_SURFACE | CLRCF_WIDTH | CLRCF_HEIGHT | CLRCF_FORMAT)) { ret = region_buffer_lock( region, surface, CSBR_FRONT ); if (ret) return ret; dfb_surface_unlock( surface ); } D_ASSERT( region->surface_lock.buffer != NULL ); } else if (region->surface_lock.buffer) { D_MAGIC_ASSERT( region->surface_lock.buffer, CoreSurfaceBuffer ); dfb_surface_unlock_buffer( region->surface_lock.buffer->surface, ®ion->surface_lock ); } D_DEBUG_AT( Core_Layers, " => setting region of '%s'\n", shared->description.name ); /* Setup hardware. */ return funcs->SetRegion( layer, layer->driver_data, layer->layer_data, region->region_data, config, flags, surface, surface ? surface->palette : NULL, ®ion->surface_lock ); }
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__ ); /* * 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->x11image_pool) dfb_surface_pool_destroy( shared->x11image_pool ); /* * Shared deinit (master only) */ fusion_call_destroy( &shared->call ); fusion_skirmish_prevail( &shared->lock ); /* close remaining windows */ for( i=0; i<dfb_layer_num(); i++ ) { CoreLayer *layer; X11LayerData *lds; layer = dfb_layer_at( i ); lds = layer->layer_data; if( lds->xw ) { dfb_x11_close_window( x11, lds->xw ); lds->xw = 0; shared->window_count--; } } fusion_skirmish_destroy( &shared->lock ); 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 void handle_expose_Async( void *ctx, void *ctx2 ) { DFBX11 *x11 = ctx; DFBX11Shared *shared = x11->shared; const XExposeEvent *expose = ctx2; CoreLayer *layer; CoreLayerContext *context; int i; X11LayerData *lds; D_DEBUG_AT( X11_Input, "%s( %d,%d-%dx%d )\n", __FUNCTION__, expose->x, expose->y, expose->width, expose->height ); //D_INFO_LINE_MSG("handle_expose %d,%d-%dx%d", expose->x, expose->y, expose->width, expose->height); /* find the correct layer */ for (i=0; i<shared->outputs; i++) { if (shared->output[i].xw && (shared->output[i].xw->window == expose->window)) break; } /* layer not found? */ if (i == shared->outputs) return; lds = shared->output[i].layers[0]; layer = dfb_layer_at( lds->layer_id ); D_ASSERT( layer != NULL ); /* Get the currently active context. */ if (dfb_layer_get_active_context( layer, &context ) == DFB_OK) { CoreLayerRegion *region; /* Get the first region. */ if (dfb_layer_context_get_primary_region( context, false, ®ion ) == DFB_OK) { /* Lock the region. */ dfb_layer_region_lock( region ); /* Get the surface of the region. */ if (region->surface && D_FLAGS_ARE_SET( region->state, CLRSF_REALIZED )) { if (dfb_config->task_manager) { DFBRegion update = { expose->x, expose->y, expose->x + expose->width - 1, expose->y + expose->height - 1 }; /* Tell the driver about the update if the region is realized. */ D_DEBUG_AT( X11_Input, " -> Issuing display task...\n" ); dfb_surface_lock( region->surface ); DisplayTask_Generate( region, &update, &update, DSFLIP_NONE, -1, NULL ); dfb_surface_unlock( region->surface ); } else { //if (lds->lock_left.buffer) { DFBRegion update = { expose->x, expose->y, expose->x + expose->width - 1, expose->y + expose->height - 1 }; // dfb_x11_update_screen( x11, lds, &update, &update, &lds->lock_left, &lds->lock_right ); //} dfb_x11_update_screen( x11, lds, &update, &update, NULL, NULL ); } } /* Unlock the region. */ dfb_layer_region_unlock( region ); /* Release the region. */ dfb_layer_region_unref( region ); } /* Release the context. */ dfb_layer_context_unref( context ); } }