From 237112bfe943581d38904eb830360f58e67bca79 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Fri, 14 Jun 2019 15:51:24 +0800 Subject: [PATCH] Implementation of GAL_SuspendVideo and GAL_ResumeVideo --- src/newgal/sysvideo.h | 233 +++++++++++++++++++++--------------------- src/newgal/video.c | 117 +++++++++++++++------ 2 files changed, 201 insertions(+), 149 deletions(-) diff --git a/src/newgal/sysvideo.h b/src/newgal/sysvideo.h index 55839c6b..ce621fc4 100644 --- a/src/newgal/sysvideo.h +++ b/src/newgal/sysvideo.h @@ -1,33 +1,33 @@ /* - * This file is part of MiniGUI, a mature cross-platform windowing + * This file is part of MiniGUI, a mature cross-platform windowing * and Graphics User Interface (GUI) support system for embedded systems * and smart IoT devices. - * + * * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. * Copyright (C) 1998~2002, WEI Yongming - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * Or, - * + * * As this program is a library, any link to this program must follow * GNU General Public License version 3 (GPLv3). If you cannot accept * GPLv3, you need to be licensed from FMSoft. - * + * * If you have got a commercial license of this program, please use it * under the terms and conditions of the commercial license. - * + * * For more information about the commercial license, please refer to * . */ @@ -56,159 +56,162 @@ typedef struct _VIDEO_MEM_INFO /* Define the GAL video driver structure */ -#define _THIS GAL_VideoDevice *_this +#define _THIS GAL_VideoDevice *_this #ifndef _STATUS -#define _STATUS GAL_status *status +#define _STATUS GAL_status *status #endif + struct GAL_VideoDevice { - /* * * */ - /* The name of this video driver */ - const char *name; + /* * * */ + /* The name of this video driver */ + const char *name; - /* * * */ - /* Initialization/Query functions */ + /* * * */ + /* Initialization/Query functions */ - /* Initialize the native video subsystem, filling 'vformat' with the - "best" display pixel format, returning 0 or -1 if there's an error. - */ - int (*VideoInit)(_THIS, GAL_PixelFormat *vformat); + /* Initialize the native video subsystem, filling 'vformat' with the + "best" display pixel format, returning 0 or -1 if there's an error. + */ + int (*VideoInit)(_THIS, GAL_PixelFormat *vformat); - /* List the available video modes for the given pixel format, sorted - from largest to smallest. - */ - GAL_Rect **(*ListModes)(_THIS, GAL_PixelFormat *format, Uint32 flags); + /* List the available video modes for the given pixel format, sorted + from largest to smallest. + */ + GAL_Rect **(*ListModes)(_THIS, GAL_PixelFormat *format, Uint32 flags); - /* Set the requested video mode, returning a surface which will be - set to the GAL_VideoSurface. The width and height will already - be verified by ListModes(), and the video subsystem is free to - set the mode to a supported bit depth different from the one - specified -- the desired bpp will be emulated with a shadow - surface if necessary. If a new mode is returned, this function - should take care of cleaning up the current mode. - */ - GAL_Surface *(*SetVideoMode)(_THIS, GAL_Surface *current, - int width, int height, int bpp, Uint32 flags); + /* Set the requested video mode, returning a surface which will be + set to the GAL_VideoSurface. The width and height will already + be verified by ListModes(), and the video subsystem is free to + set the mode to a supported bit depth different from the one + specified -- the desired bpp will be emulated with a shadow + surface if necessary. If a new mode is returned, this function + should take care of cleaning up the current mode. + */ + GAL_Surface *(*SetVideoMode)(_THIS, GAL_Surface *current, + int width, int height, int bpp, Uint32 flags); - /* Toggle the fullscreen mode */ - int (*ToggleFullScreen)(_THIS, int on); + /* Toggle the fullscreen mode */ + int (*ToggleFullScreen)(_THIS, int on); #if 0 - /* This is called after the video mode has been set, to get the - initial mouse state. It should queue events as necessary to - properly represent the current mouse focus and position. - */ - void (*UpdateMouse)(_THIS); + /* This is called after the video mode has been set, to get the + initial mouse state. It should queue events as necessary to + properly represent the current mouse focus and position. + */ + void (*UpdateMouse)(_THIS); #endif - /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) } - of the physical palette to those in 'colors'. If the device is - using a software palette (GAL_HWPALETTE not set), then the - changes are reflected in the logical palette of the screen - as well. - The return value is 1 if all entries could be set properly - or 0 otherwise. - */ - int (*SetColors)(_THIS, int firstcolor, int ncolors, - GAL_Color *colors); + /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) } + of the physical palette to those in 'colors'. If the device is + using a software palette (GAL_HWPALETTE not set), then the + changes are reflected in the logical palette of the screen + as well. + The return value is 1 if all entries could be set properly + or 0 otherwise. + */ + int (*SetColors)(_THIS, int firstcolor, int ncolors, + GAL_Color *colors); - /* This pointer should exist in the native video subsystem and should - point to an appropriate update function for the current video mode - */ - void (*UpdateRects)(_THIS, int numrects, GAL_Rect *rects); + /* This pointer should exist in the native video subsystem and should + point to an appropriate update function for the current video mode + */ + void (*UpdateRects)(_THIS, int numrects, GAL_Rect *rects); - /* Reverse the effects VideoInit() -- called if VideoInit() fails - or if the application is shutting down the video subsystem. - */ - void (*VideoQuit)(_THIS); + /* Reverse the effects VideoInit() -- called if VideoInit() fails + or if the application is shutting down the video subsystem. + */ + void (*VideoQuit)(_THIS); - /* * * */ - /* Hardware acceleration functions */ + /* * * */ + /* Hardware acceleration functions */ - /* Information about the video hardware */ - GAL_VideoInfo info; + /* Information about the video hardware */ + GAL_VideoInfo info; #ifndef _MGRM_THREADS - /* Request a surface in video memory */ - void (*RequestHWSurface)(_THIS, const REQ_HWSURFACE* request, REP_HWSURFACE* reply); + /* Request a surface in video memory */ + void (*RequestHWSurface)(_THIS, const REQ_HWSURFACE* request, REP_HWSURFACE* reply); #endif - /* Allocates a surface in video memory */ - int (*AllocHWSurface)(_THIS, GAL_Surface *surface); + /* Allocates a surface in video memory */ + int (*AllocHWSurface)(_THIS, GAL_Surface *surface); - /* Sets the hardware accelerated blit function, if any, based - on the current flags of the surface (colorkey, alpha, etc.) - */ - int (*CheckHWBlit)(_THIS, GAL_Surface *src, GAL_Surface *dst); + /* Sets the hardware accelerated blit function, if any, based + on the current flags of the surface (colorkey, alpha, etc.) + */ + int (*CheckHWBlit)(_THIS, GAL_Surface *src, GAL_Surface *dst); - /* Fills a surface rectangle with the given color */ - int (*FillHWRect)(_THIS, GAL_Surface *dst, GAL_Rect *rect, Uint32 color); + /* Fills a surface rectangle with the given color */ + int (*FillHWRect)(_THIS, GAL_Surface *dst, GAL_Rect *rect, Uint32 color); - /* Sets video mem colorkey and accelerated blit function */ - int (*SetHWColorKey)(_THIS, GAL_Surface *surface, Uint32 key); + /* Sets video mem colorkey and accelerated blit function */ + int (*SetHWColorKey)(_THIS, GAL_Surface *surface, Uint32 key); - /* Sets per surface hardware alpha value */ - int (*SetHWAlpha)(_THIS, GAL_Surface *surface, Uint8 value); - - + /* Sets per surface hardware alpha value */ + int (*SetHWAlpha)(_THIS, GAL_Surface *surface, Uint8 value); #if 0 - /* Returns a readable/writable surface */ - int (*LockHWSurface)(_THIS, GAL_Surface *surface); - void (*UnlockHWSurface)(_THIS, GAL_Surface *surface); + /* Returns a readable/writable surface */ + int (*LockHWSurface)(_THIS, GAL_Surface *surface); + void (*UnlockHWSurface)(_THIS, GAL_Surface *surface); - /* Performs hardware flipping */ - int (*FlipHWSurface)(_THIS, GAL_Surface *surface); + /* Performs hardware flipping */ + int (*FlipHWSurface)(_THIS, GAL_Surface *surface); #endif - /* Frees a previously allocated video surface */ - void (*FreeHWSurface)(_THIS, GAL_Surface *surface); + /* Frees a previously allocated video surface */ + void (*FreeHWSurface)(_THIS, GAL_Surface *surface); - Uint16 *gamma; + Uint16 *gamma; - /* * * */ - /* Data common to all drivers */ - GAL_Surface *screen; -// GAL_Surface *shadow; -// GAL_Surface *visible; - GAL_Palette *physpal; /* physical palette, if != logical palette */ - char *wm_title; - char *wm_icon; - int offset_x; - int offset_y; + /* * * */ + /* Data common to all drivers */ + GAL_Surface *screen; +// GAL_Surface *shadow; +// GAL_Surface *visible; + GAL_Palette *physpal; /* physical palette, if != logical palette */ + char *wm_title; + char *wm_icon; + int offset_x; + int offset_y; - /* Driver information flags */ - int handles_any_size; /* Driver handles any size video mode */ + /* Driver information flags */ + int handles_any_size; /* Driver handles any size video mode */ - /* * * */ - /* Data private to this driver */ - struct GAL_PrivateVideoData *hidden; + /* * * */ + /* Data private to this driver */ + struct GAL_PrivateVideoData *hidden; - /* * * */ - /* The function used to dispose of this structure */ + /* * * */ + /* The function used to dispose of this structure */ void (*free)(_THIS); - + /* DeleteSurface - called if this->info->mlt_surfaces is true * to delete a specific surface. * */ void (*DeleteSurface) (_THIS, GAL_Surface* surface); /* Set surface Palette */ int (*SetSurfaceColors) (GAL_Surface* surface, int firstcolor, int ncolors, - GAL_Color *colors); - + GAL_Color *colors); + /* Get Video Memory info */ int (*GetFBInfo) (VIDEO_MEM_INFO *video_mem_info); - - /* Set surface UpdateRects*/ + + /* Update Rects */ void (*UpdateSurfaceRects) (_THIS, GAL_Surface* surface, int numrects, GAL_Rect *rects); + /* Since 4.0.0; used for VT switching */ + int (*Suspend) (_THIS); + int (*Resume) (_THIS); }; + #undef _THIS typedef struct VideoBootStrap { - const char *name; - const char *desc; - int (*available)(void); - GAL_VideoDevice *(*create)(int devindex); + const char *name; + const char *desc; + int (*available)(void); + GAL_VideoDevice *(*create)(int devindex); } VideoBootStrap; #ifdef _MGGAL_DUMMY @@ -320,8 +323,8 @@ extern VideoBootStrap DRM_bootstrap; /* This is the current video device */ extern GAL_VideoDevice *current_video; -#define GAL_VideoSurface (current_video->screen) -#define GAL_PublicSurface (current_video->screen) +#define GAL_VideoSurface (current_video->screen) +#define GAL_PublicSurface (current_video->screen) GAL_VideoDevice *GAL_GetVideo(const char* driver_name); void Slave_FreeSurface (GAL_Surface *surface); diff --git a/src/newgal/video.c b/src/newgal/video.c index d4826086..d1a1dcb7 100644 --- a/src/newgal/video.c +++ b/src/newgal/video.c @@ -1,33 +1,33 @@ /* - * This file is part of MiniGUI, a mature cross-platform windowing + * This file is part of MiniGUI, a mature cross-platform windowing * and Graphics User Interface (GUI) support system for embedded systems * and smart IoT devices. - * + * * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. * Copyright (C) 1998~2002, WEI Yongming - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * Or, - * + * * As this program is a library, any link to this program must follow * GNU General Public License version 3 (GPLv3). If you cannot accept * GPLv3, you need to be licensed from FMSoft. - * + * * If you have got a commercial license of this program, please use it * under the terms and conditions of the commercial license. - * + * * For more information about the commercial license, please refer to * . */ @@ -356,7 +356,7 @@ static Uint8 GAL_closest_depths[4][8] = { { 0, 32, 16, 15, 24, 8, 0, 0 } }; -int GAL_VideoModeOK (int width, int height, int bpp, Uint32 flags) +int GAL_VideoModeOK (int width, int height, int bpp, Uint32 flags) { int table, b, i; int supported; @@ -406,7 +406,7 @@ int GAL_VideoModeOK (int width, int height, int bpp, Uint32 flags) --b; return(GAL_closest_depths[table][b]); } - else + else return(0); } @@ -557,12 +557,12 @@ GAL_Surface * GAL_SetVideoMode (int width, int height, int bpp, Uint32 flags) if (video->info.mlt_surfaces == 0){ if (video->SetColors) - video->SetColors(this, 0, vf->palette->ncolors, + video->SetColors(this, 0, vf->palette->ncolors, vf->palette->colors); } else{ if (video->SetSurfaceColors) - video->SetSurfaceColors(this->screen, 0, vf->palette->ncolors, + video->SetSurfaceColors(this->screen, 0, vf->palette->ncolors, vf->palette->colors); } } @@ -598,7 +598,7 @@ GAL_Surface * GAL_SetVideoMode (int width, int height, int bpp, Uint32 flags) } #ifndef _MG_MINIMALGDI - license_get_processor_id(); + license_get_processor_id(); #endif video->info.vfmt = GAL_VideoSurface->format; @@ -607,7 +607,7 @@ GAL_Surface * GAL_SetVideoMode (int width, int height, int bpp, Uint32 flags) return(GAL_PublicSurface); } -/* +/* * Convert a surface into the video pixel format. */ GAL_Surface * GAL_DisplayFormat (GAL_Surface *surface) @@ -704,7 +704,7 @@ void GAL_UpdateRect (GAL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h if (h == 0) h = screen->h; - if ((int)(x+w) > screen->w) + if ((int)(x+w) > screen->w) w = screen->w - x; if ((int)(y+h) > screen->h) h = screen->h - x; @@ -1057,7 +1057,7 @@ void gal_SlaveVideoQuit (GAL_Surface * surface) video->free(video); video = NULL; } - else{ + else{ video->DeleteSurface(video, surface); Slave_FreeSurface (surface); } @@ -1065,7 +1065,7 @@ void gal_SlaveVideoQuit (GAL_Surface * surface) return; } -static GAL_Surface *Slave_CreateSurface (GAL_VideoDevice *this, +static GAL_Surface *Slave_CreateSurface (GAL_VideoDevice *this, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) { @@ -1074,7 +1074,7 @@ static GAL_Surface *Slave_CreateSurface (GAL_VideoDevice *this, surface = (GAL_Surface *)malloc(sizeof(*surface)); if ( surface == NULL ) { - GAL_OutOfMemory(); + GAL_OutOfMemory(); return(NULL); } surface->flags = GAL_HWSURFACE; @@ -1114,11 +1114,11 @@ static GAL_Surface *Slave_CreateSurface (GAL_VideoDevice *this, /* The surface is ready to go */ surface->refcount = 1; this->info.vfmt = surface->format; - + return (surface); } -static GAL_Rect ** Slave_ListModes (GAL_VideoDevice *this, +static GAL_Rect ** Slave_ListModes (GAL_VideoDevice *this, GAL_PixelFormat *format, Uint32 flags) { GAL_Rect **modes; @@ -1135,7 +1135,7 @@ static GAL_Rect ** Slave_ListModes (GAL_VideoDevice *this, return (modes); } -static int Slave_GetVideoMode (GAL_VideoDevice *this, +static int Slave_GetVideoMode (GAL_VideoDevice *this, int *w, int *h, int *BitsPerPixel, Uint32 flags) { int table, b, i; @@ -1160,7 +1160,7 @@ static int Slave_GetVideoMode (GAL_VideoDevice *this, if (native_bpp == *BitsPerPixel) { return(1); } - + if (native_bpp > 0) { *BitsPerPixel = native_bpp; return(1); @@ -1172,11 +1172,11 @@ static int Slave_GetVideoMode (GAL_VideoDevice *this, table = ((*BitsPerPixel+7)/8)-1; GAL_closest_depths[table][0] = *BitsPerPixel; GAL_closest_depths[table][7] = surface->format->BitsPerPixel; - + for ( b = 0; !supported && GAL_closest_depths[table][b]; ++b ) { format.BitsPerPixel = GAL_closest_depths[table][b]; sizes = Slave_ListModes(this, &format, flags); - + if ( sizes == (GAL_Rect **)0 ) { /* No sizes supported at this bit-depth */ continue; @@ -1211,11 +1211,11 @@ static int Slave_GetVideoMode (GAL_VideoDevice *this, GAL_SetError("NEWGAL: No video mode large enough for " "the resolution specified.\n"); } - + return(supported); } -static GAL_Surface * Slave_SetVideoMode (GAL_VideoDevice *device, +static GAL_Surface * Slave_SetVideoMode (GAL_VideoDevice *device, GAL_Surface* surface, int width, int height, int bpp, Uint32 flags) { GAL_VideoDevice *video, *this; @@ -1233,7 +1233,7 @@ static GAL_Surface * Slave_SetVideoMode (GAL_VideoDevice *device, video_w = width; video_h = height; video_bpp = bpp; - + if (!Slave_GetVideoMode(this, &video_w, &video_h, &video_bpp, flags)){ GAL_SetError ("NEWGAL: Slave_GetVideoMode error, " "not supported video mode.\n"); @@ -1251,7 +1251,7 @@ static GAL_Surface * Slave_SetVideoMode (GAL_VideoDevice *device, video->physpal = NULL; } - if (!(video->SetVideoMode(this, surface, + if (!(video->SetVideoMode(this, surface, video_w, video_h, video_bpp, flags))) { return NULL; } @@ -1267,12 +1267,12 @@ static GAL_Surface * Slave_SetVideoMode (GAL_VideoDevice *device, vf->DitheredPalette = TRUE; if (video->info.mlt_surfaces == 0){ if (video->SetColors) - video->SetColors(this, 0, vf->palette->ncolors, + video->SetColors(this, 0, vf->palette->ncolors, vf->palette->colors); } else{ if (video->SetSurfaceColors) - video->SetSurfaceColors(surface, 0, vf->palette->ncolors, + video->SetSurfaceColors(surface, 0, vf->palette->ncolors, vf->palette->colors); } } @@ -1295,7 +1295,7 @@ static GAL_Surface * Slave_SetVideoMode (GAL_VideoDevice *device, GAL_Surface *gal_SlaveVideoInit(const char* driver_name, const char* mode, int dpi) { - GAL_Surface* surface; + GAL_Surface* surface; GAL_VideoDevice *video; GAL_PixelFormat vformat; unsigned int w, h, depth; @@ -1304,7 +1304,7 @@ GAL_Surface *gal_SlaveVideoInit(const char* driver_name, const char* mode, int d video = GAL_GetVideo(driver_name); if (video == NULL) { - _DBG_PRINTF ("NEWGAL: Does not find the slave video engine: %s.\n", + _DBG_PRINTF ("NEWGAL: Does not find the slave video engine: %s.\n", driver_name); return NULL; } @@ -1313,7 +1313,7 @@ GAL_Surface *gal_SlaveVideoInit(const char* driver_name, const char* mode, int d memset(&vformat, 0, sizeof(vformat)); if ( video->VideoInit(video, &vformat) < 0 ) { - _DBG_PRINTF ("NEWGAL: Can not init the slave video engine: %s.\n", + _DBG_PRINTF ("NEWGAL: Can not init the slave video engine: %s.\n", driver_name); gal_SlaveVideoQuit (video->screen); return NULL; @@ -1345,3 +1345,52 @@ GAL_Surface *gal_SlaveVideoInit(const char* driver_name, const char* mode, int d return surface; } +/* Since 4.0.0; activate/deactivate video device, for switching virtual terminals */ +int GAL_ResumeVideo(void) +{ +#ifdef _MGRM_PROCESSES + if (mgIsSever) { +#endif + if (current_video && current_video->Resume) { + current_video->Resume(current_video); + } +#ifdef _MGRM_PROCESSES + } +#endif + +#ifndef _MGRM_THREADS + __mg_switch_away = FALSE; +#endif + +#ifdef _MGRM_PROCESSES + UpdateTopmostLayer (NULL); +#else + SendNotifyMessage (HWND_DESKTOP, MSG_PAINT, 0, 0); +#endif + + return 0; +} + +int GAL_SuspendVideo(void) +{ +#ifdef _MGRM_PROCESSES + DisableClientsOutput (); +#endif + +#ifndef _MGRM_THREADS + __mg_switch_away = TRUE; +#endif + +#ifdef _MGRM_PROCESSES + if (mgIsSever) { +#endif + if (current_video && current_video->Suspend) { + current_video->Suspend(current_video); + } +#ifdef _MGRM_PROCESSES + } +#endif + + return 0; +} +