On Mon, 2002-05-27 at 01:22, Denis Oliver Kropp wrote:
> > For reallocate_surface(), how about just deallocating the old surface
> > and then allocate a new one with the new buffer format? And for
> > allocate_surface(), just pass a DSCAPS_FLIPPING to
> > dfb_surface_create()?
>
> The surface shouldn't be destroyed, because IDirectFBSurface for a layer's
> surface would then return DFB_DESTROYED and you would have to call
> IDirectFBDisplayLayer::GetSurface() again.
>
> However, destroying the old buffers and allocating new ones would be sufficient.
>
Okay. Here's another attempt. I've written a new function,
dfb_surface_reconfig() (for lack of a better term), that will deallocate
the old buffers and allocate new ones. Tried to incorporate this to
dfb_surface_reformat(), but the result was a mess.
I thank you in advance for any comments.
Tony
DFBResult dfb_surface_reconfig( CoreSurface *surface,
CoreSurfacePolicy policy )
{
DFBResult ret;
SurfaceBuffer *old_front, *old_back;
if (surface->front_buffer->flags & SBF_FOREIGN_SYSTEM ||
surface->back_buffer->flags & SBF_FOREIGN_SYSTEM)
{
return DFB_UNSUPPORTED;
}
dfb_surfacemanager_lock( surface->manager );
skirmish_prevail( &surface->front_lock );
skirmish_prevail( &surface->back_lock );
dfb_surfacemanager_unlock( surface->manager );
old_front = surface->front_buffer;
old_back = surface->back_buffer;
ret = dfb_surface_allocate_buffer( surface, policy, &surface->front_buffer );
if (ret) {
skirmish_dismiss( &surface->front_lock );
skirmish_dismiss( &surface->back_lock );
return ret;
}
if (surface->caps & DSCAPS_FLIPPING) {
ret = dfb_surface_allocate_buffer( surface, policy, &surface->back_buffer );
if (ret) {
dfb_surface_deallocate_buffer( surface, surface->front_buffer );
surface->front_buffer = old_front;
skirmish_dismiss( &surface->front_lock );
skirmish_dismiss( &surface->back_lock );
return ret;
}
}
else {
surface->back_buffer = surface->front_buffer;
}
dfb_surface_deallocate_buffer( surface, old_front );
if (old_front != old_back)
dfb_surface_deallocate_buffer ( surface, old_back );
dfb_surface_notify_listeners( surface, CSNF_SIZEFORMAT |
CSNF_SYSTEM | CSNF_VIDEO );
skirmish_dismiss( &surface->front_lock );
skirmish_dismiss( &surface->back_lock );
return DFB_OK;
}