📄 sdl_directfb_video.c
字号:
if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w) HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2; else HIDDEN->c2dsize.x = (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2; if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h) HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2; else HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2; #ifdef DIRECTFB_CRTC2_DEBUG printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); #endif } } 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 *) SDL_calloc (1, 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){ DFBSurfaceBlittingFlags flags = DSBLIT_NOFX; DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h }; DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h }; IDirectFBSurface *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; if (fmt->BitsPerPixel == 8) surface->SetSrcColorKeyIndex (surface, key); else /* 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){ if (HIDDEN->enable_mga_crtc2) { int rtn = surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 0); if (HIDDEN->mga_crtc2_stretch) HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); else HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); return rtn; } else 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){ if (HIDDEN->enable_mga_crtc2) { if (HIDDEN->mga_crtc2_stretch) HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, this->screen->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); else HIDDEN->c2frame->Blit(HIDDEN->c2frame, this->screen->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); }}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) { if (HIDDEN->enable_mga_crtc2) { if (HIDDEN->mga_crtc2_stretch) HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); else HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); } else surface->Flip (surface, ®ion, DSFLIP_WAITFORSYNC); }}int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors){ IDirectFBPalette *palette = this->screen->hwdata->palette; if (!palette) return 0; if (firstcolor > 255) return 0; if (firstcolor + ncolors > 256) ncolors = 256 - firstcolor; if (ncolors > 0) { int i; DFBColor entries[ncolors]; for (i=0; i<ncolors; i++) { entries[i].a = 0xff; entries[i].r = colors[i].r; entries[i].g = colors[i].g; entries[i].b = colors[i].b; } palette->SetEntries (palette, entries, ncolors, firstcolor); } return 1;} void DirectFB_VideoQuit(_THIS){ struct DirectFBEnumRect *rect = enumlist; if (this->screen && this->screen->hwdata) { IDirectFBSurface *surface = this->screen->hwdata->surface; IDirectFBPalette *palette = this->screen->hwdata->palette; if (palette) palette->Release (palette); if (surface) surface->Release (surface); this->screen->hwdata->surface = NULL; this->screen->hwdata->palette = NULL; } if (HIDDEN->c2frame) { HIDDEN->c2frame->Release (HIDDEN->c2frame); HIDDEN->c2frame = NULL; } if (HIDDEN->eventbuffer) { HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer); HIDDEN->eventbuffer = NULL; } if (HIDDEN->c2layer) { HIDDEN->c2layer->Release (HIDDEN->c2layer); HIDDEN->c2layer = NULL; } if (HIDDEN->layer) { HIDDEN->layer->Release (HIDDEN->layer); HIDDEN->layer = NULL; } if (HIDDEN->dfb) { HIDDEN->dfb->Release (HIDDEN->dfb); HIDDEN->dfb = NULL; } /* Free video mode list */ if (HIDDEN->modelist) { free (HIDDEN->modelist); HIDDEN->modelist = NULL; } /* Free mode enumeration list */ while (rect) { struct DirectFBEnumRect *next = rect->next; free (rect); rect = next; } enumlist = NULL; HIDDEN->initialized = 0;}int DirectFB_ShowWMCursor(_THIS, WMcursor *cursor){ /* We can only hide or show the default cursor */ if ( cursor == NULL ) { HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0x00); } else { HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0xFF); } return 1;}void DirectFB_FinalQuit(void) {}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -