📄 sdl_directfb_video.c
字号:
this->info.wm_available = 1;
this->info.hw_available = 1;
this->info.blit_hw = 1;
this->info.blit_hw_CC = 1;
this->info.blit_hw_A = 1;
this->info.blit_fill = 1;
this->info.video_mem = caps.video_memory / 1024;
HIDDEN->initialized = 1;
HIDDEN->dfb = dfb;
HIDDEN->layer = layer;
HIDDEN->eventbuffer = eventbuffer;
return 0;
}
static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
if (flags & SDL_FULLSCREEN)
return HIDDEN->SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
else
if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN)
return (SDL_Rect**) -1;
return NULL;
}
SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
{
DFBResult ret;
DFBSurfaceDescription dsc;
DFBSurfacePixelFormat pixelformat;
fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
width, height, bpp, flags);
flags |= SDL_FULLSCREEN;
/* Release previous primary surface */
if (current->hwdata && current->hwdata->surface)
{
current->hwdata->surface->Release (current->hwdata->surface);
current->hwdata->surface = NULL;
}
else if (!current->hwdata)
{
/* Allocate the hardware acceleration data */
current->hwdata = (struct private_hwdata *) malloc (sizeof(*current->hwdata));
if (!current->hwdata)
{
SDL_OutOfMemory();
return NULL;
}
memset (current->hwdata, 0, sizeof(*current->hwdata));
}
/* Set cooperative level depending on flag SDL_FULLSCREEN */
if (flags & SDL_FULLSCREEN)
{
ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN);
if (ret)
{
DirectFBError ("dfb->SetCooperativeLevel", ret);
flags &= ~SDL_FULLSCREEN;
}
}
else
HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
/* Set video mode */
ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
if (ret)
{
if (flags & SDL_FULLSCREEN)
{
flags &= ~SDL_FULLSCREEN;
HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
}
if (ret)
{
SetDirectFBerror ("dfb->SetVideoMode", ret);
return NULL;
}
}
/* Create primary surface */
dsc.flags = DSDESC_CAPS;
dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, ¤t->hwdata->surface);
if (ret && (flags & SDL_DOUBLEBUF))
{
/* Try without double buffering */
dsc.caps &= ~DSCAPS_FLIPPING;
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, ¤t->hwdata->surface);
}
if (ret)
{
SetDirectFBerror ("dfb->CreateSurface", ret);
current->hwdata->surface = NULL;
return NULL;
}
current->w = width;
current->h = height;
current->flags = SDL_HWSURFACE | SDL_PREALLOC;
if (flags & SDL_FULLSCREEN)
{
current->flags |= SDL_FULLSCREEN;
this->UpdateRects = DirectFB_DirectUpdate;
}
else
this->UpdateRects = DirectFB_WindowedUpdate;
if (dsc.caps & DSCAPS_FLIPPING)
current->flags |= SDL_DOUBLEBUF;
current->hwdata->surface->GetPixelFormat (current->hwdata->surface, &pixelformat);
DFBToSDLPixelFormat (pixelformat, current->format);
return current;
}
static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface)
{
DFBResult ret;
DFBSurfaceDescription dsc;
/* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n",
surface->w, surface->h, surface->format->BitsPerPixel, surface->flags);*/
if (surface->w < 8 || surface->h < 8)
return -1;
/* fill surface description */
dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
dsc.width = surface->w;
dsc.height = surface->h;
dsc.caps = surface->flags & SDL_DOUBLEBUF ? DSCAPS_FLIPPING : 0;
/* find the right pixelformat */
dsc.pixelformat = SDLToDFBPixelFormat (surface->format);
if (dsc.pixelformat == DSPF_UNKNOWN)
return -1;
/* Allocate the hardware acceleration data */
surface->hwdata = (struct private_hwdata *) malloc (sizeof(*surface->hwdata));
if (surface->hwdata == NULL)
{
SDL_OutOfMemory();
return -1;
}
/* Create the surface */
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface->hwdata->surface);
if (ret)
{
SetDirectFBerror ("dfb->CreateSurface", ret);
free (surface->hwdata);
surface->hwdata = NULL;
return -1;
}
surface->flags |= SDL_HWSURFACE | SDL_PREALLOC;
return 0;
}
static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface)
{
if (surface->hwdata && HIDDEN->initialized)
{
surface->hwdata->surface->Release (surface->hwdata->surface);
free (surface->hwdata);
surface->hwdata = NULL;
}
}
static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
{
/* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n",
src->hwdata, dst->hwdata);*/
if (!src->hwdata || !dst->hwdata)
return 0;
src->flags |= SDL_HWACCEL;
src->map->hw_blit = DirectFB_HWAccelBlit;
return 1;
}
static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
{
DFBRectangle sr, dr;
IDirectFBSurface *surface;
DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
sr.x = srcrect->x;
sr.y = srcrect->y;
sr.w = srcrect->w;
sr.h = srcrect->h;
dr.x = dstrect->x;
dr.y = dstrect->y;
dr.w = dstrect->w;
dr.h = dstrect->h;
surface = dst->hwdata->surface;
if (src->flags & SDL_SRCCOLORKEY)
{
flags |= DSBLIT_SRC_COLORKEY;
DirectFB_SetHWColorKey (NULL, src, src->format->colorkey);
}
if (src->flags & SDL_SRCALPHA)
{
flags |= DSBLIT_BLEND_COLORALPHA;
surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha);
}
surface->SetBlittingFlags (surface, flags);
if (sr.w == dr.w && sr.h == dr.h)
surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y);
else
surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr);
return 0;
}
static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
{
SDL_PixelFormat *fmt = dst->format;
IDirectFBSurface *surface = dst->hwdata->surface;
/* ugly */
surface->SetColor (surface,
(color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
(color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
(color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), 0xFF);
surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, dstrect->h);
return 0;
}
static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *src, Uint32 key)
{
SDL_PixelFormat *fmt = src->format;
IDirectFBSurface *surface = src->hwdata->surface;
/* ugly */
surface->SetSrcColorKey (surface,
(key & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
(key & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
(key & fmt->Bmask) << (fmt->Bloss - fmt->Bshift));
return 0;
}
static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha)
{
return 0;
}
static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface)
{
return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC);
}
static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface)
{
DFBResult ret;
void *data;
int pitch;
ret = surface->hwdata->surface->Lock (surface->hwdata->surface,
DSLF_WRITE, &data, &pitch);
if (ret)
{
SetDirectFBerror ("surface->Lock", ret);
return -1;
}
surface->pixels = data;
surface->pitch = pitch;
return 0;
}
static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
surface->hwdata->surface->Unlock (surface->hwdata->surface);
surface->pixels = NULL;
}
static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
{
}
static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects)
{
DFBRegion region;
int i;
int region_valid = 0;
IDirectFBSurface *surface = this->screen->hwdata->surface;
for (i=0; i<numrects; ++i)
{
int x2, y2;
if ( ! rects[i].w ) /* Clipped? */
continue;
x2 = rects[i].x + rects[i].w - 1;
y2 = rects[i].y + rects[i].h - 1;
if (region_valid)
{
if (rects[i].x < region.x1)
region.x1 = rects[i].x;
if (rects[i].y < region.y1)
region.y1 = rects[i].y;
if (x2 > region.x2)
region.x2 = x2;
if (y2 > region.y2)
region.y2 = y2;
}
else
{
region.x1 = rects[i].x;
region.y1 = rects[i].y;
region.x2 = x2;
region.y2 = y2;
region_valid = 1;
}
}
if (region_valid)
surface->Flip (surface, ®ion, DSFLIP_WAITFORSYNC);
}
int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
fprintf(stderr, "SDL: Unimplemented DirectFB_SetColors!\n");
return 0;
}
void DirectFB_VideoQuit(_THIS)
{
int i, j;
HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer);
HIDDEN->layer->Release (HIDDEN->layer);
HIDDEN->dfb->Release (HIDDEN->dfb);
/* Free video mode lists */
for ( i=0; i<NUM_MODELISTS; ++i )
{
if ( HIDDEN->SDL_modelist[i] != NULL )
{
for ( j=0; HIDDEN->SDL_modelist[i][j]; ++j )
free(HIDDEN->SDL_modelist[i][j]);
free(HIDDEN->SDL_modelist[i]);
HIDDEN->SDL_modelist[i] = NULL;
}
}
HIDDEN->initialized = 0;
}
void DirectFB_FinalQuit(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -