--- SDL_sysvideo.cc.org 2003-10-12 01:25:48.000000000 +0900 +++ SDL_sysvideo.cc 2003-11-18 03:04:21.000000000 +0900 @@ -31,20 +31,31 @@ #include #include #include +#include +#include #include #include #include #include +#include +#include +#include #include #include #include +#include +#include +#include +#include +#include #include "SDL.h" #include "SDL_timer.h" #include "SDL_QWin.h" +#include "SDL_sysvideo.h" extern "C" { @@ -88,22 +99,26 @@ typedef enum { MACHINE_SHARP_SL5000D, MACHINE_SHARP_SL5500, + MACHINE_SHARP_SL6000, // 詳しいことわからんけどとりあえず MACHINE_SHARP_SLA300, MACHINE_SHARP_SLB500, MACHINE_SHARP_SLC700, MACHINE_SHARP_SLC750, MACHINE_SHARP_SLC760, + MACHINE_SHARP_SLC860, // 詳しいことわからんけどとりあえず MACHINE_MAX } machine_t; static const machine_spec_t st_machine_spec[] = { { "Sharp", "SL-5000D", 0 }, { "Sharp", "SL-5500", 0 }, + { "Sharp", "SL-6000", 0 }, // 詳しいことわからんけどとりあえず { "Sharp", "SL-A300", 0 }, { "Sharp", "SL-B500", 0 }, { "Sharp", "SL-C700", 0 }, { "Sharp", "SL-C750", 0 }, { "Sharp", "SL-C760", 0 }, + { "Sharp", "SL-C860", 0 }, // 詳しいことわからんけどとりあえず }; /* Name of the environment variable used to invert the screen rotation or not: @@ -132,6 +147,20 @@ static int QT_IconifyWindow(_THIS); static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode); + static int console_fd; + struct fb_var_screeninfo saved_vinfo; + int fb_hwrot; + int fb_direct; + static int isKHloaded; + bool is_VGA_machine; + +#define W100FB_CONFIG 0x57415200 /* WAL\00 */ +#define W100INIT_ITEM 0 +#define W100INIT_ALL 1 +#define W100INIT_ITEM_WITH_VAL 2 +#define W100FB_CONFIG_EX 0x57415202 /* WAL\02 */ + + /* FB driver bootstrap functions */ static int QT_Available(void) @@ -276,13 +305,34 @@ int QT_VideoInit(_THIS, SDL_PixelFormat *vformat) { - /* Initialize the QPE Application */ + const char *SDL_fbdev; + struct fb_var_screeninfo vinfo; + + /* Initialize the QPE Application */ /* Determine the screen depth */ vformat->BitsPerPixel = QPixmap::defaultDepth(); // For now we hardcode the current depth because anything else // might as well be emulated by SDL rather than by Qtopia. + //frame buffer device open. + SDL_fbdev = getenv("SDL_FBDEV"); + if ( SDL_fbdev == NULL ) { + SDL_fbdev = "/dev/fb0"; + } + console_fd = open(SDL_fbdev, O_RDWR, 0); + if ( console_fd < 0 ) { + SDL_SetError("Unable to open %s", SDL_fbdev); + return(-1); + } + + if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { + SDL_SetError("Couldn't get console pixel format"); + QT_VideoQuit(_this); + return(-1); + } + saved_vinfo = vinfo; + QSize desktop_size = qApp->desktop()->size(); QT_AddMode(_this, ((vformat->BitsPerPixel+7)/8)-1, desktop_size.width(), desktop_size.height()); @@ -300,12 +350,20 @@ if (!st_logfp) st_logfp = stderr; #endif + + + QT_GrabInput(_this, SDL_GRAB_ON); { QCopEnvelope e("QPE/KeyHelper", "repeater(int)"); e << 2; } + isKHloaded=(fopen("/home/zaurus/Settings/keyhelper_SDL.xml","r") != NULL) ? 1 : 0; + if (isKHloaded) { + system("qcop QPE/KeyHelper \"reload(QString)\" keyhelper_SDL.xml"); //QcopEnvelope can't use. + LOG("keyhelper_SDL.xml loaded\n"); + } return(0); } @@ -328,6 +386,7 @@ /* Various screen update functions available */ static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); + static void QT_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); static int QT_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen) @@ -349,11 +408,13 @@ fp = fopen("/proc/deviceinfo/product", "rb"); if (fp) { if (fread(buf, 1, sizeof(buf), fp) > 0) { - LOG("QT_GetMachine: /proc/deviceinfo/product is '%s'\n", buf); +// LOG("QT_GetMachine: /proc/deviceinfo/product is %s\n", buf); if (strncmp(buf, "SL-A300", 7) == 0) machine = MACHINE_SHARP_SLA300; else if (strncmp(buf, "SL-5500", 7) == 0) machine = MACHINE_SHARP_SL5500; + else if (strncmp(buf, "SL-6000", 7) == 0) // 詳しいことわからんけどとりあえず + machine = MACHINE_SHARP_SL6000; else if (strncmp(buf, "SL-B500", 7) == 0) machine = MACHINE_SHARP_SLB500; else if (strncmp(buf, "SL-C700", 7) == 0) @@ -362,6 +423,8 @@ machine = MACHINE_SHARP_SLC750; else if (strncmp(buf, "SL-C760", 7) == 0) machine = MACHINE_SHARP_SLC760; + else if (strncmp(buf, "SL-C860", 7) == 0) // 詳しいことわからんけどとりあえず + machine = MACHINE_SHARP_SLC860; } fclose(fp); } else { @@ -425,6 +488,20 @@ QSize qteSize = qApp->desktop()->size(); QSize fbSize; QSize userSize; + int fb_xres; + int fb_yres; + struct fb_var_screeninfo vinfo; + struct fb_fix_screeninfo finfo; + int tmp_ioctl_data; + char fb_size_fix = ' '; + bool isW100patch_kernel = false; + int numFb_Size; + + int mapped_memlen; + int mapped_offset; + void *mapped_mem; + int fb_offset; + machine_t machine = QT_GetMachine(_this); machine_spec_t machineSpec = st_machine_spec[machine]; @@ -432,9 +509,174 @@ int qteKeyRotation, sdlKeyRotation; bool isQteQvga; + if (machine == MACHINE_SHARP_SLC700 || + machine == MACHINE_SHARP_SLC750 || + machine == MACHINE_SHARP_SLC760 || + machine == MACHINE_SHARP_SLC860 || // 詳しいことわからんけどとりあえず + machine == MACHINE_SHARP_SL6000 ) { // 詳しいことわからんけどとりあえず + is_VGA_machine = true; + }else { + is_VGA_machine = false; + } + // qte での回転角度を取得 QT_GetQteServerSpec(_this, &qteRotation, &isQteQvga); + // SL-C700 のスタイル + bool isInputStyle = false; + if (is_VGA_machine) { + int status = system("/home/QtPalmtop/bin/chkhinge"); + if (WEXITSTATUS(status) != 2) + isInputStyle = true; + LOG("QT_SetVideoMode: SL-C700 Style is %s\n", + isInputStyle ? "Input style" : "View style"); + } + + + // specity screen setting + if (is_VGA_machine) { + + // w100 rotation pached kernel check + isW100patch_kernel = (fopen("/proc/driver/w100/rotation","r") != NULL) ? true : false; + LOG("Your Kernel is %s\n",isW100patch_kernel ? "Special Kernel" : "Normal Kernel"); + + const char *envFb_Size = getenv("SDL_FB_SIZE"); + if (envFb_Size !=NULL) { + numFb_Size=sscanf(envFb_Size,"%dx%d%c",&fb_xres,&fb_yres,&fb_size_fix); + } else { + numFb_Size=0; + } + + if (numFb_Size >=2) { + + // specity screen mode + if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { + SDL_SetError("Couldn't get console pixel format"); + QT_VideoQuit(_this); + return(NULL); + } + + vinfo.xres = fb_xres; + vinfo.xres_virtual = fb_xres; + vinfo.yres = fb_yres; + vinfo.yres_virtual = fb_yres; + + if (fb_size_fix == '@') { + width = fb_xres; + height = fb_yres; + } + + if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { + SDL_SetError("Couldn't set console screen info"); + return(NULL); + } + + + if (isW100patch_kernel) { + qteSize.setWidth(vinfo.xres); + qteSize.setHeight(vinfo.yres); + qteRotation=0; + }else if(vinfo.xres == 320){ + qteSize.setWidth(vinfo.xres); + qteSize.setHeight(vinfo.yres); + qteRotation=2; + }else { + qteSize.setWidth(vinfo.yres); + qteSize.setHeight(vinfo.xres); + qteRotation=3; + } + + if (isW100patch_kernel && (vinfo.xres == 320) && (vinfo.yres == 240)) { + tmp_ioctl_data=121; + ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data); + fb_hwrot=1; + } + + LOG("FBVideoMode: %dx%d%c\n", vinfo.xres, vinfo.yres,fb_size_fix ); + + }else { + + // auto screen mode + if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { + SDL_SetError("Couldn't get console pixel format"); + QT_VideoQuit(_this); + return(NULL); + } + + if (isW100patch_kernel && (isInputStyle == false) && (vinfo.xres == 240) && (vinfo.yres == 320)) { + vinfo.xres = 240; + vinfo.xres_virtual = 240; + vinfo.yres = 320; + vinfo.yres_virtual = 320; + qteRotation=0; + }else if ((width <= 320) && (height <= 240)) { + vinfo.xres = 320; + vinfo.xres_virtual = 320; + vinfo.yres = 240; + vinfo.yres_virtual = 240; + }else if (isW100patch_kernel && (isInputStyle == true)){ + vinfo.xres = 640; + vinfo.xres_virtual = 640; + vinfo.yres = 480; + vinfo.yres_virtual = 480; + qteRotation=0; + }else { + vinfo.xres = 480; + vinfo.xres_virtual = 480; + vinfo.yres = 640; + vinfo.yres_virtual = 640; + } + + if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { + SDL_SetError("Couldn't set console screen info"); + return(NULL); + } + + if (isW100patch_kernel) { + qteSize.setWidth(vinfo.xres); + qteSize.setHeight(vinfo.yres); + qteRotation=0; + fb_direct=1; + }else if(vinfo.xres == 320){ + qteSize.setWidth(vinfo.xres); + qteSize.setHeight(vinfo.yres); + qteRotation=2; + }else { + qteSize.setWidth(vinfo.yres); + qteSize.setHeight(vinfo.xres); + qteRotation=3; + } + + if (isW100patch_kernel && (vinfo.xres == 320) && (vinfo.yres == 240)) { + tmp_ioctl_data=121; + ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data); + fb_hwrot=1; + qteRotation=0; + } + + LOG("FBVideoMode: %dx%d%c\n", vinfo.xres, vinfo.yres,fb_size_fix ); + } + } + + // direct paint setting + const char *envFb_Direct = getenv("SDL_FB_DIRECT"); + if (envFb_Direct !=NULL) + fb_direct = envFb_Direct ? atoi(envFb_Direct) : -1; + + if (fb_direct == 1){ + if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { + SDL_SetError("Couldn't get console hardware info"); + QT_VideoQuit(_this); + return(NULL); + } + if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { + SDL_SetError("Couldn't get console pixel format"); + QT_VideoQuit(_this); + return(NULL); + } + LOG("Direct paint mode\n"); + } + // hack for SL-5500 if (machine == MACHINE_SHARP_SL5500) qteRotation = 3; @@ -442,11 +684,7 @@ // SL-B500 用ハック(とりあえず、ね) if (machine == MACHINE_SHARP_SLB500) qteRotation = 3; -#if 0 - // SL-C750/760 用ハック(Thanks to 浜地さん) - if (machine == MACHINE_SHARP_SLC750 || machine == MACHINE_SHARP_SLC760) - qteRotation = (qteRotation + 2) & 3; -#endif + // 生フレームバッファのサイズを得る if (qteRotation & 1) { fbSize.setWidth(qteSize.height()); @@ -465,18 +703,6 @@ userSize = fbSize; } - // SL-C700 のスタイル - bool isInputStyle = false; - if (machine == MACHINE_SHARP_SLC700 || - machine == MACHINE_SHARP_SLC750 || - machine == MACHINE_SHARP_SLC760 ) { - int status = system("/home/QtPalmtop/bin/chkhinge"); - if (WEXITSTATUS(status) != 2) - isInputStyle = true; - LOG("QT_SetVideoMode: SL-C700 Style is %s\n", - isInputStyle ? "Input style" : "View style"); - } - // まず、要求されたウィンドウサイズがユーザの望む回転角度のスクリーンに // 収まるのかをチェック。 if (width <= userSize.width() && height <= userSize.height()) { @@ -486,10 +712,7 @@ else { // で、その指定が無いのであれば qte の回転角度に合わせるだけ // なんだけど、SL-C700 ではちょい複雑。 - if ((machine == MACHINE_SHARP_SLC700 || - machine == MACHINE_SHARP_SLC750 || - machine == MACHINE_SHARP_SLC760) && - fbSize.width() == 320 && fbSize.height() == 240) { + if (is_VGA_machine && (fbSize.width() == 320) && (fbSize.height() == 240)) { if (isInputStyle) sdlRotation = 2; else @@ -500,11 +723,7 @@ } } else if (width <= fbSize.width() && height <= fbSize.height()) { sdlRotation = 0; - if ((machine == MACHINE_SHARP_SLC700 || - machine == MACHINE_SHARP_SLC750 || - machine == MACHINE_SHARP_SLC760) && - fbSize.width() == 320 && fbSize.height() == 240 - && isInputStyle) + if (is_VGA_machine && (fbSize.width() == 320) && (fbSize.height() == 240) && isInputStyle) sdlRotation = 2; } else if (width <= fbSize.height() && height <= fbSize.width()) { sdlRotation = 1; @@ -513,13 +732,13 @@ return NULL; } + if (fb_hwrot == 1) + sdlRotation = 0; + if (getenv(SDL_QT_INVERT_ROTATION_ENV_NAME) != NULL) { sdlRotation = (sdlRotation + 2) & 3; } -#if 0 - if (machine == MACHINE_SHARP_SLC750 || machine == MACHINE_SHARP_SLC760) - sdlRotation = (sdlRotation + 2) & 3; -#endif + LOG("QT_SetVideoMode: argSize=%dx%d\n", width, height); LOG("QT_SetVideoMode: qteSize=%dx%d\n", qteSize.width(), qteSize.height()); @@ -542,13 +761,14 @@ qteKeyRotation = qteRotation; // fprintf(stderr, "%d\n", (machine == MACHINE_SHARP_SLC700)); // fprintf(stderr, "%d\n", isQteQvga); - if (isQteQvga && (machine == MACHINE_SHARP_SLC700 || - machine == MACHINE_SHARP_SLC750 || - machine == MACHINE_SHARP_SLC760)) + if (isQteQvga && is_VGA_machine) qteKeyRotation = 3; else if (machine == MACHINE_SHARP_SLB500) qteKeyRotation = 3; + if (isQteQvga && fb_hwrot == 1) + qteKeyRotation = 1; + sdlKeyRotation = sdlRotation; SDL_Win->setKeyRotation(sdlKeyRotation, qteKeyRotation); @@ -556,25 +776,51 @@ LOG("QT_SetVideoMode: qteKeyRotation=%d\n", qteKeyRotation); LOG("QT_SetVideoMode: sdlKeyRotation=%d\n", sdlKeyRotation); -// if (isSlc700 && isQvga) -// SDL_Win->setSLC700InputFix(true); - if ( flags & SDL_OPENGL ) { SDL_SetError("OpenGL not supported"); return(NULL); } /* Create the QImage framebuffer */ - qimage = new QImage(current->w, current->h, bpp); - if (qimage->isNull()) { - SDL_SetError("Couldn't create screen bitmap"); - delete qimage; - return(NULL); + + // frame buffer memory mapping + if (fb_direct == 1) { + current->pitch = finfo.line_length; + current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); + mapped_offset = (((long)finfo.smem_start) - + (((long)finfo.smem_start)&~(PAGE_SIZE-1))); + mapped_memlen = finfo.smem_len+mapped_offset; + if(console_fd >0 ) { + mapped_mem = mmap(NULL, mapped_memlen,PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0); + fb_offset=(vinfo.xres-width)+(vinfo.yres-height)*vinfo.xres; + current->pixels = (void *)((int )mapped_mem+fb_offset); + _this->UpdateRects = QT_DirectUpdate; + } else { + qimage = new QImage(current->w, current->h, bpp); + if (qimage->isNull()) { + SDL_SetError("Couldn't create screen bitmap"); + delete qimage; + return(NULL); + } + current->pixels = (void *)qimage->bits(); + _this->UpdateRects = QT_NormalUpdate; + SDL_Win->setImage(qimage); +// SDL_Win->setFullscreen(true); //comment to non update taskbar + } + } else { + qimage = new QImage(current->w, current->h, bpp); + if (qimage->isNull()) { + SDL_SetError("Couldn't create screen bitmap"); + delete qimage; + return(NULL); + } + current->pitch = qimage->bytesPerLine(); + current->pixels = (void *)qimage->bits(); + _this->UpdateRects = QT_NormalUpdate; + SDL_Win->setImage(qimage); +// SDL_Win->setFullscreen(true); //comment to non update taskbar + } - current->pitch = qimage->bytesPerLine(); - current->pixels = (void *)qimage->bits(); - SDL_Win->setImage(qimage); - _this->UpdateRects = QT_NormalUpdate; - SDL_Win->setFullscreen(true); + // fprintf(stderr,"QT_SetVideoMode() qImage:%dx%d %d\n", // qimage->width(), qimage->height(), qimage->bytesPerLine()); @@ -629,6 +875,12 @@ SDL_Win->unlockScreen(); } } + + static void QT_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) + { + + } + /* Is the system palette settable? */ int QT_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) { @@ -644,6 +896,21 @@ // -- David Hedbor // delete SDL_Win; // SDL_Win = 0; + + if ( console_fd > 0 ) { + /* Restore the original video mode and palette */ + if (fb_hwrot == 1) { + int tmp_ioctl_data=120; + ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data); + } + + ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo); + + /* We're all done with the framebuffer */ + close(console_fd); + console_fd = -1; + } + _this->screen->pixels = NULL; QT_GrabInput(_this, SDL_GRAB_OFF); @@ -651,8 +918,13 @@ QCopEnvelope e("QPE/KeyHelper", "repeater(int)"); e << 1; } + if (isKHloaded) + system("qcop QPE/KeyHelper \"reload()\""); //QcopEnvelope can't use. + } + + static int QT_IconifyWindow(_THIS) { SDL_Win->hide();