📄 sdl_ph_video.c
字号:
/* 16 bit RGB */ {0xF800, 0x07E0, 0x001F, 0x0000, 16}, /* 24 bit RGB */ {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24}, /* 32 bit ARGB */ {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32}, }; switch (bpp) { case 8: return &phColorMasks[0]; case 15: return &phColorMasks[1]; case 16: return &phColorMasks[2]; case 24: return &phColorMasks[3]; case 32: return &phColorMasks[4]; } return NULL;}static int ph_VideoInit(_THIS, SDL_PixelFormat* vformat){ PgHWCaps_t hwcaps; int i; window=NULL; desktoppal=SDLPH_PAL_NONE;#if SDL_VIDEO_OPENGL oglctx=NULL; oglbuffers=NULL; oglflags=0; oglbpp=0;#endif old_video_mode=-1; old_refresh_rate=-1; if (NULL == (phevent = SDL_malloc(EVENT_SIZE))) { SDL_OutOfMemory(); return -1; } SDL_memset(phevent, 0x00, EVENT_SIZE); window = ph_CreateWindow(this); if (window == NULL) { SDL_SetError("ph_VideoInit(): Couldn't create video window !\n"); return -1; } /* Create the blank cursor */ SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, (int)BLANK_CHOTX, (int)BLANK_CHOTY); if (SDL_BlankCursor == NULL) { return -1; } if (PgGetGraphicsHWCaps(&hwcaps) < 0) { SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n"); this->FreeWMCursor(this, SDL_BlankCursor); return -1; } if (PgGetVideoModeInfo(hwcaps.current_video_mode, &desktop_mode) < 0) { SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n"); this->FreeWMCursor(this, SDL_BlankCursor); return -1; } /* Determine the current screen size */ this->info.current_w = desktop_mode.width; this->info.current_h = desktop_mode.height; /* We need to return BytesPerPixel as it in used by CreateRGBsurface */ vformat->BitsPerPixel = desktop_mode.bits_per_pixel; vformat->BytesPerPixel = desktop_mode.bytes_per_scanline/desktop_mode.width; desktopbpp = desktop_mode.bits_per_pixel; /* save current palette */ if (desktopbpp==8) { PgGetPalette(savedpal); PgGetPalette(syspalph); } else { for(i=0; i<_Pg_MAX_PALETTE; i++) { savedpal[i]=PgRGB(0, 0, 0); syspalph[i]=PgRGB(0, 0, 0); } } currently_fullscreen = 0; currently_hided = 0; currently_maximized = 0; current_overlay = NULL; OCImage.direct_context = NULL; OCImage.offscreen_context = NULL; OCImage.offscreen_backcontext = NULL; OCImage.oldDC = NULL; OCImage.CurrentFrameData = NULL; OCImage.FrameData0 = NULL; OCImage.FrameData1 = NULL; videomode_emulatemode = 0; this->info.wm_available = 1; ph_UpdateHWInfo(this); return 0;}static SDL_Surface* ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags){ const struct ColourMasks* mask; /* Lock the event thread, in multi-threading environments */ SDL_Lock_EventThread(); current->flags = flags; /* if we do not have desired fullscreen mode, then fallback into window mode */ if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0)) { current->flags &= ~SDL_FULLSCREEN; current->flags &= ~SDL_NOFRAME; current->flags &= ~SDL_RESIZABLE; } ph_SetupWindow(this, width, height, current->flags); mask = ph_GetColourMasks(bpp); if (mask != NULL) { SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0); } else { SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); return NULL; } if ((current->flags & SDL_OPENGL)==SDL_OPENGL) {#if !SDL_VIDEO_OPENGL /* if no built-in OpenGL support */ SDL_SetError("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n"); current->flags &= ~SDL_OPENGL; return NULL;#endif /* SDL_VIDEO_OPENGL */ } else { /* Initialize internal variables */ if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { if (bpp==8) { desktoppal=SDLPH_PAL_SYSTEM; } current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ current->flags |= SDL_HWSURFACE; } else { /* remove this if we'll have support for the non-fullscreen sw/hw+doublebuf one day */ current->flags &= ~SDL_DOUBLEBUF; /* Use offscreen memory if SDL_HWSURFACE flag is set */ if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { if (desktopbpp!=bpp) { current->flags &= ~SDL_HWSURFACE; } } /* using palette emulation code in window mode */ if (bpp==8) { if (desktopbpp>=15) { desktoppal = SDLPH_PAL_EMULATE; } else { desktoppal = SDLPH_PAL_SYSTEM; } } else { desktoppal = SDLPH_PAL_NONE; } } } current->w = width; current->h = height; if (desktoppal==SDLPH_PAL_SYSTEM) { current->flags|=SDL_HWPALETTE; } /* Must call at least once for setup image planes */ if (ph_SetupUpdateFunction(this, current, current->flags)==-1) { /* Error string was filled in the ph_SetupUpdateFunction() */ return NULL; } /* finish window drawing, if we are not in fullscreen, of course */ if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { PtFlush(); } else { PgFlush(); } visualbpp=bpp; ph_UpdateHWInfo(this); SDL_Unlock_EventThread(); /* We've done! */ return (current);}static void ph_VideoQuit(_THIS){ /* restore palette */ if (desktopbpp==8) { PgSetPalette(syspalph, 0, -1, 0, 0, 0); PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); PgFlush(); } ph_DestroyImage(this, SDL_VideoSurface); if (window) { PtUnrealizeWidget(window); PtDestroyWidget(window); window=NULL; } if (phevent!=NULL) { SDL_free(phevent); phevent=NULL; }}static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors){ int i; SDL_Rect updaterect; updaterect.x = updaterect.y = 0; updaterect.w = this->screen->w; updaterect.h = this->screen->h; /* palette emulation code, using palette of the PhImage_t struct */ if (desktoppal==SDLPH_PAL_EMULATE) { if ((SDL_Image) && (SDL_Image->palette)) { for (i=firstcolor; i<firstcolor+ncolors; i++) { syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); SDL_Image->palette[i] = syspalph[i]; } /* image needs to be redrawn */ this->UpdateRects(this, 1, &updaterect); } } else { if (desktoppal==SDLPH_PAL_SYSTEM) { for (i=firstcolor; i<firstcolor+ncolors; i++) { syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); } if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { /* window mode must use soft palette */ PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); /* image needs to be redrawn */ this->UpdateRects(this, 1, &updaterect); } else { /* fullscreen mode must use hardware palette */ PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); } } else { /* SDLPH_PAL_NONE do nothing */ } } return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -