--- uae/src/sdlgfx.c 2018/04/24 17:16:21 1.1.1.4 +++ uae/src/sdlgfx.c 2018/04/24 17:21:40 1.1.1.6 @@ -52,18 +52,10 @@ static SDL_Surface *screen; static int x_size_table[MAX_SCREEN_MODES] = { 320, 320, 320, 320, 640, 640, 640, 800, 1024, 1152, 1280 }; static int y_size_table[MAX_SCREEN_MODES] = { 200, 240, 256, 400, 350, 480, 512, 600, 768, 864, 1024 }; -/* Supported SDL screen modes */ -#define MAX_SDL_SCREENMODE 32 -SDL_Rect screenmode[MAX_SDL_SCREENMODE]; -int mode_count; - -static int sdlgfx_init_ok; - static int red_bits, green_bits, blue_bits; static int red_shift, green_shift, blue_shift; #ifdef PICASSO96 -static int screen_is_picasso; static char picasso_invalid_lines[1201]; static int picasso_has_invalid_lines; static int picasso_invalid_start, picasso_invalid_stop; @@ -84,7 +76,7 @@ static SDL_Color p96Colors[256]; #endif static int ncolors; -static int fullscreen; +static int fullscreen, prev_fullscreen; static int mousegrab; static int is_hwsurface; @@ -237,27 +229,25 @@ static int find_best_mode (int *width, i /* First test whether the specified mode is supported */ found = SDL_VideoModeOK (*width, *height, depth, *try_fs ? SDL_FULLSCREEN : 0); - if (!found && mode_count > 0) { + if (!found && n_fullscreen_modes > 0) { /* The specified mode wasn't available, so we'll try and find * a supported resolution which best matches it. */ int i; write_log ("SDLGFX: Requested mode (%dx%d%d) not available.\n", *width, *height, depth); - /* Note: the screenmode array should already be sorted from largest to smallest, since - * that's the order SDL gives us the screenmodes. */ - for (i = mode_count - 1; i >= 0; i--) { - if (screenmode[i].w >= *width && screenmode[i].h >= *height) + for (i = 0; i < n_fullscreen_modes; i--) { + if (gfx_fullscreen_modes[i].w >= *width && gfx_fullscreen_modes[i].h >= *height) break; } /* If we didn't find a mode, use the largest supported mode */ - if (i < 0) - i = 0; + if (i == n_fullscreen_modes) + i = n_fullscreen_modes - 1; - *width = screenmode[i].w; - *height = screenmode[i].h; - found = 1; + *width = gfx_fullscreen_modes[i].w; + *height = gfx_fullscreen_modes[i].h; + found = 1; write_log ("SDLGFX: Using mode (%dx%d)\n", *width, *height); } @@ -344,7 +334,7 @@ static int get_p96_pixel_format (const s * Returns a count of the number of supported modes, -1 if any mode is supported, * or 0 if there are no modes with this pixel format. */ -static long find_screen_modes (struct SDL_PixelFormat *vfmt, SDL_Rect *mode_list, int mode_list_size) +static void find_screen_modes (struct SDL_PixelFormat *vfmt) { long count = 0; SDL_Rect **modes = SDL_ListModes (vfmt, SDL_FULLSCREEN | SDL_HWSURFACE); @@ -355,19 +345,29 @@ static long find_screen_modes (struct SD int h = -1; /* Filter list of modes SDL gave us and ignore duplicates */ - for (i = 0; modes[i] && count < mode_list_size; i++) { + for (i = 0; modes[i]; i++) + if (modes[i]->w != w || modes[i]->h != h) { + count++; + h = modes[i]->h; + w = modes[i]->w; + } + + gfx_fullscreen_modes = malloc (sizeof (struct uae_rect) * count); + n_fullscreen_modes = count; + + w = h = -1; + for (i = count = 0; count < n_fullscreen_modes; i++) { if (modes[i]->w != w || modes[i]->h != h) { - mode_list[count].w = w = modes[i]->w; - mode_list[count].h = h = modes[i]->h; + /* Fill the array in reverse, as SDL gives us a list of + screenmodes sorted largest to smallest. */ + gfx_fullscreen_modes[n_fullscreen_modes - 1 - count].w = w = modes[i]->w; + gfx_fullscreen_modes[n_fullscreen_modes - 1 - count].h = h = modes[i]->h; count++; write_log ("SDLGFX: Found screenmode: %dx%d.\n", w, h); } } - } else - count = (long) modes; - - return count; + } } /** @@ -429,7 +429,6 @@ int graphics_setup (void) int result = 0; if (SDL_InitSubSystem (SDL_INIT_VIDEO) == 0) { - const SDL_version *version = SDL_Linked_Version (); const SDL_VideoInfo *info = SDL_GetVideoInfo (); @@ -443,17 +442,16 @@ int graphics_setup (void) write_log ("SDLGFX: Display is %d bits deep.\n", bitdepth); /* Build list of screenmodes */ - mode_count = find_screen_modes (info->vfmt, &screenmode[0], MAX_SDL_SCREENMODE); + find_screen_modes (info->vfmt); result = 1; - sdlgfx_init_ok = 1; } else write_log ("SDLGFX: initialization failed - %s\n", SDL_GetError()); return result; } -static int graphics_subinit (void) +int graphics_subinit (void) { Uint32 uiSDLVidModFlags = 0; @@ -472,7 +470,7 @@ static int graphics_subinit (void) curr_gfx = &currprefs.gfx_f; else curr_gfx = &currprefs.gfx_w; - + current_width = curr_gfx->width; current_height = curr_gfx->height; } @@ -482,6 +480,12 @@ static int graphics_subinit (void) gfxvidinfo.height = current_height; } + if (!fullscreen && prev_fullscreen) { + struct uae_rect *biggest = gfx_fullscreen_modes + n_fullscreen_modes - 1; + /* Try switching back to the previous screenmode. */ + SDL_SetVideoMode (biggest->w, biggest->h, bitdepth, SDL_FULLSCREEN); + } + if (bitdepth == 8) uiSDLVidModFlags |= SDL_HWPALETTE; if (fullscreen) { @@ -541,6 +545,8 @@ static int graphics_subinit (void) inputdevice_release_all_keys (); reset_hotkeys (); + bit_unit = display->format->BytesPerPixel * 8; + #ifdef PICASSO96 if (!screen_is_picasso) { #endif @@ -559,20 +565,18 @@ static int graphics_subinit (void) gfxvidinfo.maxblocklines = gfxvidinfo.height; } gfxvidinfo.linemem = 0; - gfxvidinfo.pixbytes = display->format->BytesPerPixel; - bit_unit = display->format->BytesPerPixel * 8; + gfxvidinfo.pixbytes = bit_unit >> 3; gfxvidinfo.rowbytes = display->pitch; SDL_SetColors (display, arSDLColors, 0, 256); - reset_drawing (); - /* Force recalculation of row maps - if we're locking */ old_pixels = (void *)-1; #ifdef PICASSO96 } else { /* Initialize structure for Picasso96 video modes */ + picasso_vidinfo.pixbytes = bit_unit >> 3; picasso_vidinfo.rowbytes = display->pitch; picasso_vidinfo.extra_mem = 1; picasso_vidinfo.depth = bitdepth; @@ -604,8 +608,8 @@ int graphics_init (void) #endif mousegrab = 0; - fixup_prefs_dimensions (&currprefs.gfx_w); - fixup_prefs_dimensions (&currprefs.gfx_f); + fixup_prefs_dimensions (&currprefs.gfx_w, gfx_windowed_modes, n_windowed_modes); + fixup_prefs_dimensions (&currprefs.gfx_f, gfx_fullscreen_modes, n_fullscreen_modes); if (graphics_subinit ()) { if (init_colors ()) { @@ -615,7 +619,7 @@ int graphics_init (void) return success; } -static void graphics_subshutdown (int final) +void graphics_subshutdown (int final) { DEBUG_LOG ("Function: graphics_subshutdown\n"); @@ -627,9 +631,14 @@ static void graphics_subshutdown (int fi by reinitializing SDL. */ SDL_QuitSubSystem (SDL_INIT_VIDEO); SDL_InitSubSystem (SDL_INIT_VIDEO); - if (fullscreen) + + prev_fullscreen = fullscreen; + + if (final && prev_fullscreen) { + struct uae_rect *biggest = gfx_fullscreen_modes + n_fullscreen_modes - 1; /* Try switching back to the previous screenmode. */ - SDL_SetVideoMode (screenmode[0].w, screenmode[0].h, bitdepth, SDL_FULLSCREEN); + SDL_SetVideoMode (biggest->w, biggest->h, bitdepth, SDL_FULLSCREEN); + } display = screen = 0; @@ -658,70 +667,70 @@ void handle_events (void) while (SDL_PollEvent (&rEvent)) { switch (rEvent.type) { - case SDL_QUIT: - DEBUG_LOG ("Event: quit\n"); - uae_quit(); - break; - - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: { - int state = (rEvent.type == SDL_MOUSEBUTTONDOWN); - int buttonno = -1; - - DEBUG_LOG ("Event: mouse button %d %s\n", rEvent.button.button, state ? "down" : "up"); - - switch (rEvent.button.button) { - case SDL_BUTTON_LEFT: buttonno = 0; break; - case SDL_BUTTON_MIDDLE: buttonno = 2; break; - case SDL_BUTTON_RIGHT: buttonno = 1; break; + case SDL_QUIT: + DEBUG_LOG ("Event: quit\n"); + uae_quit (); + break; + + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: { + int state = (rEvent.type == SDL_MOUSEBUTTONDOWN); + int buttonno = -1; + + DEBUG_LOG ("Event: mouse button %d %s\n", rEvent.button.button, state ? "down" : "up"); + + switch (rEvent.button.button) { + case SDL_BUTTON_LEFT: buttonno = 0; break; + case SDL_BUTTON_MIDDLE: buttonno = 2; break; + case SDL_BUTTON_RIGHT: buttonno = 1; break; #ifdef SDL_BUTTON_WHEELUP - case SDL_BUTTON_WHEELUP: if (state) record_key (0x7a << 1); break; - case SDL_BUTTON_WHEELDOWN: if (state) record_key (0x7b << 1); break; + case SDL_BUTTON_WHEELUP: if (state) record_key (0x7a << 1); break; + case SDL_BUTTON_WHEELDOWN: if (state) record_key (0x7b << 1); break; #endif - } - if (buttonno >= 0) - setmousebuttonstate (0, buttonno, rEvent.type == SDL_MOUSEBUTTONDOWN ? 1:0); - break; } + if (buttonno >= 0) + setmousebuttonstate (0, buttonno, rEvent.type == SDL_MOUSEBUTTONDOWN ? 1:0); + break; + } - case SDL_KEYUP: - case SDL_KEYDOWN: { - int state = (rEvent.type == SDL_KEYDOWN); - int keycode; - int ievent; - - keycode = rEvent.key.keysym.sym; - - DEBUG_LOG ("Event: key %d %s\n", keycode, state ? "down" : "up"); - - if ((ievent = match_hotkey_sequence (keycode, state))) { - DEBUG_LOG ("Hotkey event: %d\n", ievent); - handle_hotkey_event (ievent, state); - } else { - inputdevice_do_keyboard (keysym2amiga (keycode), state); - } - break; + case SDL_KEYUP: + case SDL_KEYDOWN: { + int state = (rEvent.type == SDL_KEYDOWN); + int keycode; + int ievent; + + keycode = rEvent.key.keysym.sym; + + DEBUG_LOG ("Event: key %d %s\n", keycode, state ? "down" : "up"); + + if ((ievent = match_hotkey_sequence (keycode, state))) { + DEBUG_LOG ("Hotkey event: %d\n", ievent); + handle_hotkey_event (ievent, state); + } else { + inputdevice_do_keyboard (keysym2amiga (keycode), state); } + break; + } - case SDL_MOUSEMOTION: - //DEBUG_LOG ("Event: mouse motion\n"); + case SDL_MOUSEMOTION: + //DEBUG_LOG ("Event: mouse motion\n"); - if (!fullscreen && !mousegrab) { - setmousestate (0, 0,rEvent.motion.x, 1); - setmousestate (0, 1,rEvent.motion.y, 1); - } else { - setmousestate (0, 0, rEvent.motion.xrel, 0); - setmousestate (0, 1, rEvent.motion.yrel, 0); - } - break; + if (!fullscreen && !mousegrab) { + setmousestate (0, 0,rEvent.motion.x, 1); + setmousestate (0, 1,rEvent.motion.y, 1); + } else { + setmousestate (0, 0, rEvent.motion.xrel, 0); + setmousestate (0, 1, rEvent.motion.yrel, 0); + } + break; - case SDL_ACTIVEEVENT: - if (rEvent.active.state & SDL_APPINPUTFOCUS && !rEvent.active.gain) { - DEBUG_LOG ("Lost input focus\n"); - inputdevice_release_all_keys (); - reset_hotkeys (); - } - break; + case SDL_ACTIVEEVENT: + if (rEvent.active.state & SDL_APPINPUTFOCUS && !rEvent.active.gain) { + DEBUG_LOG ("Lost input focus\n"); + inputdevice_release_all_keys (); + reset_hotkeys (); + } + break; } /* end switch() */ } /* end while() */ @@ -761,53 +770,6 @@ static void switch_keymaps (void) set_default_hotkeys (get_default_cooked_hotkeys ()); } -int check_prefs_changed_gfx (void) -{ - int a_changed = 0, p_changed = 0; - - if (!screen_is_picasso) { - if (!fullscreen - && memcmp (&changed_prefs.gfx_w, &currprefs.gfx_w, sizeof (struct gfx_params)) != 0) - { - a_changed = 1; - fixup_prefs_dimensions (&changed_prefs.gfx_w); - currprefs.gfx_w = changed_prefs.gfx_w; - } else if (fullscreen - && memcmp (&changed_prefs.gfx_f, &currprefs.gfx_f, sizeof (struct gfx_params)) != 0) - { - a_changed = 1; - fixup_prefs_dimensions (&changed_prefs.gfx_f); - currprefs.gfx_f = changed_prefs.gfx_f; - } - if (changed_prefs.gfx_afullscreen != currprefs.gfx_afullscreen) { - a_changed = 1; - } - } else if (changed_prefs.gfx_pfullscreen != currprefs.gfx_pfullscreen) { - p_changed = 1; - } - - currprefs.gfx_afullscreen = changed_prefs.gfx_afullscreen; - currprefs.gfx_pfullscreen = changed_prefs.gfx_pfullscreen; - - if (!a_changed && !p_changed) - return 0; - - DEBUG_LOG ("Function: check_prefs_changed_gfx\n"); - - graphics_subshutdown (0); - - gui_update_gfx (); - - graphics_subinit (); - - notice_screen_contents_lost (); - init_row_map (); - if (screen_is_picasso) - picasso_enablescreen (1); - - return 0; -} - int debuggable (void) { return 1; @@ -977,12 +939,12 @@ int DX_FillResolutions (uae_u16 *ppixel_ } /* Check list of supported SDL screenmodes */ - for (i = 0; i < mode_count; i++) { + for (i = 0; i < n_fullscreen_modes; i++) { int j; int found = 0; for (j = 0; j < MAX_SCREEN_MODES - 1; j++) { - if (screenmode[i].w == x_size_table[j] && - screenmode[i].h == y_size_table[j]) + if (gfx_fullscreen_modes[i].w == x_size_table[j] && + gfx_fullscreen_modes[i].h == y_size_table[j]) { found = 1; break; @@ -992,61 +954,13 @@ int DX_FillResolutions (uae_u16 *ppixel_ /* If SDL mode is not a standard P96 mode (and thus already added to the * list, above) then add it */ if (!found) - add_p96_mode (screenmode[i].w, screenmode[i].h, emulate_chunky, &count); + add_p96_mode (gfx_fullscreen_modes[i].w, gfx_fullscreen_modes[i].h, + emulate_chunky, &count); } return count; } -static void set_window_for_picasso (void) -{ - DEBUG_LOG ("Function: set_window_for_picasso\n"); -#if 0 - if (current_width == picasso_vidinfo.width && current_height == picasso_vidinfo.height) - return; -#endif - - graphics_subshutdown(0); - graphics_subinit(); -} - -void gfx_set_picasso_modeinfo (int w, int h, int depth, int rgbfmt) -{ - DEBUG_LOG ("Function: gfx_set_picasso_modeinfo w: %i h: %i depth: %i rgbfmt: %i\n", w, h, depth, rgbfmt); - - if (screen_is_picasso - && picasso_vidinfo.width == w - && picasso_vidinfo.height == h) - return; - - picasso_vidinfo.width = w; - picasso_vidinfo.height = h; - picasso_vidinfo.depth = depth; - picasso_vidinfo.pixbytes = bit_unit >> 3; - if (screen_is_picasso) - set_window_for_picasso(); -} - -void gfx_set_picasso_baseaddr (uaecptr a) -{ -} - -void gfx_set_picasso_state (int on) -{ - DEBUG_LOG ("Function: gfx_set_picasso_state: %d\n", on); - - if (on == screen_is_picasso) - return; - - graphics_subshutdown (0); - screen_is_picasso = on; - - graphics_subinit (); - - if (on) - DX_SetPalette (0, 256); -} - uae_u8 *gfx_lock_picasso (void) { DEBUG_LOG ("Function: gfx_lock_picasso\n"); @@ -1091,11 +1005,6 @@ void toggle_mousegrab (void) } } -void screenshot (int mode) -{ - write_log ("Screenshot not supported yet\n"); -} - /* * Mouse inputdevice functions */ @@ -1130,7 +1039,7 @@ static void unacquire_mouse (unsigned in return; } -static unsigned int get_mouse_num (void) +static int get_mouse_num (void) { return 1; } @@ -1140,7 +1049,7 @@ static const char *get_mouse_name (unsig return "Default mouse"; } -static unsigned int get_mouse_widget_num (unsigned int mouse) +static int get_mouse_widget_num (unsigned int mouse) { return MAX_AXES + MAX_BUTTONS; } @@ -1191,7 +1100,7 @@ struct inputdevice_functions inputdevice /* * Keyboard inputdevice functions */ -static unsigned int get_kb_num (void) +static int get_kb_num (void) { /* SDL supports only one keyboard */ return 1; @@ -1202,7 +1111,7 @@ static const char *get_kb_name (unsigned return "Default keyboard"; } -static unsigned int get_kb_widget_num (unsigned int kb) +static int get_kb_widget_num (unsigned int kb) { return 255; // fix me } @@ -1303,11 +1212,11 @@ void input_get_default_mouse (struct uae * Handle gfx specific cfgfile options */ -void target_save_options (FILE *f, struct uae_prefs *p) +void target_save_options (FILE *f, const struct uae_prefs *p) { } -int target_parse_option (struct uae_prefs *p, char *option, char *value) +int target_parse_option (struct uae_prefs *p, const char *option, const char *value) { return 0; }