src/osd/sdl/drawogl.c
| r2988 | r2989 | |
| 160 | 160 | struct _sdl_info |
| 161 | 161 | { |
| 162 | 162 | INT32 blittimer; |
| 163 | UINT32 extra_flags; |
| 163 | 164 | |
| 164 | 165 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 165 | 166 | SDL_GLContext gl_context_id; |
| r2988 | r2989 | |
| 197 | 198 | |
| 198 | 199 | int totalColors; // total colors from machine/sdl_window_config/sdl_window_info |
| 199 | 200 | |
| 201 | float last_hofs; |
| 202 | float last_vofs; |
| 203 | |
| 200 | 204 | // Static vars from draogl_window_dra |
| 201 | | INT32 old_blitwidth; |
| 202 | | INT32 old_blitheight; |
| 203 | 205 | INT32 surf_w; |
| 204 | 206 | INT32 surf_h; |
| 205 | 207 | GLfloat texVerticex[8]; |
| r2988 | r2989 | |
| 292 | 294 | // core functions |
| 293 | 295 | |
| 294 | 296 | static void drawogl_exit(void); |
| 297 | static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window); |
| 295 | 298 | static int drawogl_window_create(sdl_window_info *window, int width, int height); |
| 296 | 299 | static void drawogl_window_resize(sdl_window_info *window, int width, int height); |
| 297 | 300 | static void drawogl_window_destroy(sdl_window_info *window); |
| r2988 | r2989 | |
| 299 | 302 | static const render_primitive_list *drawogl_window_get_primitives(sdl_window_info *window); |
| 300 | 303 | static void drawogl_destroy_all_textures(sdl_window_info *window); |
| 301 | 304 | static void drawogl_window_clear(sdl_window_info *window); |
| 305 | static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 302 | 306 | |
| 303 | 307 | |
| 304 | 308 | |
| r2988 | r2989 | |
| 389 | 393 | // drawogl_init |
| 390 | 394 | //============================================================ |
| 391 | 395 | |
| 392 | | int drawogl_init(sdl_draw_callbacks *callbacks) |
| 396 | int drawogl_init(sdl_draw_info *callbacks) |
| 393 | 397 | { |
| 394 | 398 | // fill in the callbacks |
| 395 | 399 | callbacks->exit = drawogl_exit; |
| 396 | | callbacks->window_create = drawogl_window_create; |
| 397 | | callbacks->window_resize = drawogl_window_resize; |
| 398 | | callbacks->window_get_primitives = drawogl_window_get_primitives; |
| 399 | | callbacks->window_draw = drawogl_window_draw; |
| 400 | | callbacks->window_destroy = drawogl_window_destroy; |
| 401 | | callbacks->window_destroy_all_textures = drawogl_destroy_all_textures; |
| 402 | | callbacks->window_clear = drawogl_window_clear; |
| 400 | callbacks->attach = drawogl_attach; |
| 403 | 401 | |
| 404 | 402 | dll_loaded = 0; |
| 405 | 403 | |
| 406 | | #if SDL_VERSION_ATLEAST(1,3,0) |
| 407 | | mame_printf_verbose("Using SDL multi-window OpenGL driver (SDL 1.3+)\n"); |
| 408 | | #else |
| 409 | | mame_printf_verbose("Using SDL single-window OpenGL driver (SDL 1.2)\n"); |
| 410 | | #endif |
| 404 | if (SDL_VERSION_ATLEAST(1,3,0)) |
| 405 | mame_printf_verbose("Using SDL multi-window OpenGL driver (SDL 1.3+)\n"); |
| 406 | else |
| 407 | mame_printf_verbose("Using SDL single-window OpenGL driver (SDL 1.2)\n"); |
| 411 | 408 | return 0; |
| 412 | 409 | } |
| 413 | 410 | |
| 411 | |
| 414 | 412 | //============================================================ |
| 413 | // drawogl_attach |
| 414 | //============================================================ |
| 415 | |
| 416 | static void drawogl_attach(sdl_draw_info *info, sdl_window_info *window) |
| 417 | { |
| 418 | // fill in the callbacks |
| 419 | window->create = drawogl_window_create; |
| 420 | window->resize = drawogl_window_resize; |
| 421 | window->get_primitives = drawogl_window_get_primitives; |
| 422 | window->draw = drawogl_window_draw; |
| 423 | window->destroy = drawogl_window_destroy; |
| 424 | window->destroy_all_textures = drawogl_destroy_all_textures; |
| 425 | window->clear = drawogl_window_clear; |
| 426 | window->xy_to_render_target = drawogl_xy_to_render_target; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | //============================================================ |
| 415 | 431 | // Load the OGL function addresses |
| 416 | 432 | //============================================================ |
| 417 | 433 | |
| r2988 | r2989 | |
| 454 | 470 | * directfb and and x11 use this env var |
| 455 | 471 | * SDL_VIDEO_GL_DRIVER |
| 456 | 472 | */ |
| 457 | | const char *e; |
| 473 | const char *stemp; |
| 458 | 474 | |
| 459 | | e=getenv(SDLENV_GL_LIB); |
| 460 | | |
| 461 | | #ifdef SDLMAME_MACOSX |
| 462 | | /* Vas Crabb: Default GL-lib for MACOSX */ |
| 463 | | if (!e) |
| 464 | | e = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"; |
| 465 | | #endif |
| 466 | | if (SDL_GL_LoadLibrary(e) != 0) // Load library (default for e==NULL |
| 475 | stemp = options_get_string(mame_options(), SDLOPTION_GL_LIB); |
| 476 | if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) == 0) |
| 477 | stemp = NULL; |
| 478 | |
| 479 | if (SDL_GL_LoadLibrary(stemp) != 0) // Load library (default for e==NULL |
| 467 | 480 | { |
| 468 | | fatalerror("Unable to load default library: %s\n", e); |
| 481 | fatalerror("Unable to load opengl library: %s\n", stemp ? stemp : "<default>"); |
| 469 | 482 | } |
| 470 | | mame_printf_verbose("Loaded opengl shared library: %s\n", e ? e : "<default>"); |
| 483 | mame_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>"); |
| 471 | 484 | gl_dispatch = auto_malloc(sizeof(osd_gl_dispatch)); |
| 472 | 485 | dll_loaded=1; |
| 473 | 486 | } |
| r2988 | r2989 | |
| 492 | 505 | window->dxdata = sdl; |
| 493 | 506 | |
| 494 | 507 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 495 | | window->extra_flags = (window->fullscreen ? |
| 508 | sdl->extra_flags = (window->fullscreen ? |
| 496 | 509 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE); |
| 497 | | window->extra_flags |= SDL_WINDOW_OPENGL; |
| 510 | sdl->extra_flags |= SDL_WINDOW_OPENGL; |
| 498 | 511 | |
| 499 | 512 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 500 | 513 | load_gl_lib(); |
| 501 | 514 | |
| 502 | 515 | // create the SDL window |
| 503 | 516 | SDL_SelectVideoDisplay(window->monitor->handle); |
| 504 | | SDL_SetFullscreenDisplayMode(NULL); // Use desktop |
| 517 | |
| 518 | if (window->fullscreen && video_config.switchres) |
| 519 | { |
| 520 | SDL_DisplayMode mode; |
| 521 | SDL_GetCurrentDisplayMode(&mode); |
| 522 | mode.w = width; |
| 523 | mode.h = height; |
| 524 | SDL_SetFullscreenDisplayMode(&mode); // Try to set mode |
| 525 | } |
| 526 | else |
| 527 | SDL_SetFullscreenDisplayMode(NULL); // Use desktop |
| 528 | |
| 505 | 529 | window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 506 | | width, height, window->extra_flags); |
| 507 | | #if 0 |
| 508 | | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) ) |
| 530 | width, height, sdl->extra_flags); |
| 531 | |
| 532 | if (!(SDL_GetWindowFlags(window->window_id) & SDL_WINDOW_OPENGL) ) |
| 509 | 533 | { |
| 510 | | fprintf(stderr, "OpenGL not supported on this driver!\n"); |
| 534 | mame_printf_error("OpenGL not supported on this driver!\n"); |
| 511 | 535 | return 1; |
| 512 | 536 | } |
| 513 | | #endif |
| 537 | |
| 514 | 538 | SDL_ShowWindow(window->window_id); |
| 515 | 539 | SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 516 | 540 | SDL_RaiseWindow(window->window_id); |
| r2988 | r2989 | |
| 519 | 543 | sdl->gl_context_id = SDL_GL_CreateContext(window->window_id); |
| 520 | 544 | |
| 521 | 545 | #else |
| 522 | | window->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 523 | | window->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 546 | sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 547 | sdl->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 524 | 548 | |
| 525 | 549 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 526 | 550 | #if (SDL_VERSION_ATLEAST(1,2,10)) |
| r2988 | r2989 | |
| 532 | 556 | |
| 533 | 557 | // create the SDL surface (which creates the window in windowed mode) |
| 534 | 558 | sdl->sdlsurf = SDL_SetVideoMode(width, height, |
| 535 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 559 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 536 | 560 | |
| 537 | 561 | if (!sdl->sdlsurf) |
| 538 | 562 | return 1; |
| r2988 | r2989 | |
| 542 | 566 | |
| 543 | 567 | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) ) |
| 544 | 568 | { |
| 545 | | fprintf(stderr, "OpenGL not supported on this driver!\n"); |
| 569 | mame_printf_error("OpenGL not supported on this driver!\n"); |
| 546 | 570 | return 1; |
| 547 | 571 | } |
| 548 | 572 | |
| r2988 | r2989 | |
| 551 | 575 | |
| 552 | 576 | #endif |
| 553 | 577 | sdl->totalColors = window->totalColors; |
| 554 | | sdl->old_blitwidth = 0; |
| 555 | | sdl->old_blitheight = 0; |
| 556 | 578 | sdl->blittimer = 0; |
| 557 | 579 | sdl->surf_w = 0; |
| 558 | 580 | sdl->surf_h = 0; |
| r2988 | r2989 | |
| 737 | 759 | SDL_FreeSurface(sdl->sdlsurf); |
| 738 | 760 | |
| 739 | 761 | sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 740 | | SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 762 | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 741 | 763 | window->width = sdl->sdlsurf->w; |
| 742 | 764 | window->height = sdl->sdlsurf->h; |
| 743 | 765 | |
| 744 | 766 | #endif |
| 745 | | sdl->init_context = 0; |
| 767 | sdl->init_context = 1; |
| 746 | 768 | |
| 747 | 769 | } |
| 748 | 770 | |
| 749 | 771 | //============================================================ |
| 772 | // drawsdl_xy_to_render_target |
| 773 | //============================================================ |
| 774 | |
| 775 | static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 776 | { |
| 777 | sdl_info *sdl = window->dxdata; |
| 778 | |
| 779 | *xt = x - sdl->last_hofs; |
| 780 | *yt = y - sdl->last_vofs; |
| 781 | if (*xt<0 || *xt >= window->blitwidth) |
| 782 | return 0; |
| 783 | if (*yt<0 || *xt >= window->blitheight) |
| 784 | return 0; |
| 785 | return 1; |
| 786 | } |
| 787 | |
| 788 | //============================================================ |
| 750 | 789 | // drawogl_window_get_primitives |
| 751 | 790 | //============================================================ |
| 752 | 791 | |
| r2988 | r2989 | |
| 768 | 807 | // loadGLExtensions |
| 769 | 808 | //============================================================ |
| 770 | 809 | |
| 771 | | static void loadGLExtensions(sdl_info *sdl) |
| 810 | static void loadGLExtensions(sdl_window_info *window) |
| 772 | 811 | { |
| 812 | sdl_info *sdl = window->dxdata; |
| 773 | 813 | static int _once = 1; |
| 774 | 814 | |
| 775 | 815 | // sdl->usevbo=FALSE; // You may want to switch VBO and PBO off, by uncommenting this statement |
| r2988 | r2989 | |
| 978 | 1018 | |
| 979 | 1019 | if ( sdl->useglsl ) |
| 980 | 1020 | { |
| 981 | | if ( video_config.prescale != 1 ) |
| 1021 | if ( window->prescale != 1 ) |
| 982 | 1022 | { |
| 983 | 1023 | sdl->useglsl = 0; |
| 984 | 1024 | if (_once) |
| r2988 | r2989 | |
| 986 | 1026 | mame_printf_warning("OpenGL: GLSL supported, but disabled due to: prescale !=1 \n"); |
| 987 | 1027 | } |
| 988 | 1028 | } |
| 989 | | if ( video_config.prescale_effect != 0 ) |
| 1029 | if ( window->prescale_effect != 0 ) |
| 990 | 1030 | { |
| 991 | 1031 | sdl->useglsl = 0; |
| 992 | 1032 | if (_once) |
| r2988 | r2989 | |
| 1107 | 1147 | } |
| 1108 | 1148 | |
| 1109 | 1149 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1110 | | //SDL_SelectRenderer(window->window_id); |
| 1111 | 1150 | SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id); |
| 1112 | 1151 | #endif |
| 1113 | 1152 | if (sdl->init_context) |
| r2988 | r2989 | |
| 1127 | 1166 | sdl->blittimer--; |
| 1128 | 1167 | } |
| 1129 | 1168 | |
| 1130 | | if (sdl->init_context || (sdl->old_blitwidth != window->blitwidth) || (sdl->old_blitheight != window->blitheight)) |
| 1131 | | { |
| 1132 | | glClear(GL_COLOR_BUFFER_BIT); |
| 1133 | | |
| 1134 | | sdl->old_blitwidth = window->blitwidth; |
| 1135 | | sdl->old_blitheight = window->blitheight; |
| 1136 | | |
| 1137 | | sdl->blittimer = 2; |
| 1138 | | } |
| 1139 | | |
| 1140 | 1169 | if ( !sdl->initialized || |
| 1141 | 1170 | window->width!= sdl->surf_w || window->height!= sdl->surf_h ) |
| 1142 | 1171 | { |
| 1143 | 1172 | if ( !sdl->initialized ) |
| 1144 | 1173 | { |
| 1145 | | loadGLExtensions(sdl); |
| 1174 | loadGLExtensions(window); |
| 1146 | 1175 | } |
| 1147 | 1176 | |
| 1148 | 1177 | sdl->surf_w=window->width; |
| r2988 | r2989 | |
| 1231 | 1260 | } |
| 1232 | 1261 | } |
| 1233 | 1262 | |
| 1263 | sdl->last_hofs = hofs; |
| 1264 | sdl->last_vofs = vofs; |
| 1265 | |
| 1234 | 1266 | osd_lock_acquire(window->primlist->lock); |
| 1235 | 1267 | |
| 1236 | 1268 | // now draw |
| r2988 | r2989 | |
| 1253 | 1285 | curPrimitive=GL_LINES; |
| 1254 | 1286 | } |
| 1255 | 1287 | |
| 1256 | | if(pendingPrimitive!=GL_NO_PRIMITIVE && pendingPrimitive!=curPrimitive) |
| 1288 | if(pendingPrimitive!=GL_NO_PRIMITIVE && pendingPrimitive!=curPrimitive) |
| 1257 | 1289 | { |
| 1258 | 1290 | glEnd(); |
| 1259 | 1291 | pendingPrimitive=GL_NO_PRIMITIVE; |
| r2988 | r2989 | |
| 1664 | 1696 | return (needPow2)?gl_round_to_pow2(v):v; |
| 1665 | 1697 | } |
| 1666 | 1698 | |
| 1667 | | static void texture_compute_size_subroutine(sdl_info *sdl, texture_info *texture, UINT32 flags, |
| 1699 | static void texture_compute_size_subroutine(sdl_window_info *window, texture_info *texture, UINT32 flags, |
| 1668 | 1700 | UINT32 width, UINT32 height, |
| 1669 | 1701 | int* p_width, int* p_height, int* p_width_create, int* p_height_create) |
| 1670 | 1702 | { |
| 1671 | | int width_create; |
| 1672 | | int height_create; |
| 1703 | sdl_info *sdl = window->dxdata; |
| 1704 | int width_create; |
| 1705 | int height_create; |
| 1673 | 1706 | |
| 1674 | 1707 | if ( texture->texpow2 ) |
| 1675 | 1708 | { |
| r2988 | r2989 | |
| 1692 | 1725 | texture->xprescale--; |
| 1693 | 1726 | while (texture->yprescale > 1 && height_create * texture->yprescale > sdl->texture_max_height) |
| 1694 | 1727 | texture->yprescale--; |
| 1695 | | if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != video_config.prescale || texture->yprescale != video_config.prescale)) |
| 1696 | | mame_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", video_config.prescale, video_config.prescale, texture->xprescale, texture->yprescale); |
| 1728 | if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window->prescale || texture->yprescale != window->prescale)) |
| 1729 | mame_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window->prescale, window->prescale, texture->xprescale, texture->yprescale); |
| 1697 | 1730 | |
| 1698 | 1731 | width *= texture->xprescale; |
| 1699 | 1732 | height *= texture->yprescale; |
| r2988 | r2989 | |
| 1715 | 1748 | *p_height_create=height_create; |
| 1716 | 1749 | } |
| 1717 | 1750 | |
| 1718 | | static void texture_compute_size_type(sdl_info *sdl, const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1751 | static void texture_compute_size_type(sdl_window_info *window, const render_texinfo *texsource, texture_info *texture, UINT32 flags) |
| 1719 | 1752 | { |
| 1753 | sdl_info *sdl = window->dxdata; |
| 1720 | 1754 | int finalheight, finalwidth; |
| 1721 | 1755 | int finalheight_create, finalwidth_create; |
| 1722 | 1756 | |
| r2988 | r2989 | |
| 1729 | 1763 | |
| 1730 | 1764 | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1731 | 1765 | |
| 1732 | | texture_compute_size_subroutine(sdl, texture, flags, texsource->width, texsource->height, |
| 1766 | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1733 | 1767 | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1734 | 1768 | |
| 1735 | 1769 | // if we added pixels for the border, and that just barely pushed us over, take it back |
| r2988 | r2989 | |
| 1741 | 1775 | |
| 1742 | 1776 | texture_compute_type_subroutine(sdl, texsource, texture, flags); |
| 1743 | 1777 | |
| 1744 | | texture_compute_size_subroutine(sdl, texture, flags, texsource->width, texsource->height, |
| 1778 | texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, |
| 1745 | 1779 | &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); |
| 1746 | 1780 | } |
| 1747 | 1781 | |
| r2988 | r2989 | |
| 2244 | 2278 | texture->texinfo.seqid = -1; // force set data |
| 2245 | 2279 | if (PRIMFLAG_GET_SCREENTEX(flags)) |
| 2246 | 2280 | { |
| 2247 | | texture->xprescale = video_config.prescale; |
| 2248 | | texture->yprescale = video_config.prescale; |
| 2249 | | texture->prescale_effect = video_config.prescale_effect; |
| 2281 | texture->xprescale = window->prescale; |
| 2282 | texture->yprescale = window->prescale; |
| 2283 | texture->prescale_effect = window->prescale_effect; |
| 2250 | 2284 | } |
| 2251 | 2285 | else |
| 2252 | 2286 | { |
| r2988 | r2989 | |
| 2305 | 2339 | } |
| 2306 | 2340 | |
| 2307 | 2341 | // compute the size |
| 2308 | | texture_compute_size_type(sdl, texsource, texture, flags); |
| 2342 | texture_compute_size_type(window, texsource, texture, flags); |
| 2309 | 2343 | |
| 2310 | | texture->pbo=0; |
| 2344 | texture->pbo=0; |
| 2311 | 2345 | |
| 2312 | 2346 | if ( texture->type != TEXTURE_TYPE_SHADER && sdl->useglsl) |
| 2313 | 2347 | { |
| r2988 | r2989 | |
| 2708 | 2742 | if (container!=NULL) |
| 2709 | 2743 | { |
| 2710 | 2744 | render_container_user_settings settings; |
| 2711 | | |
| 2712 | 2745 | render_container_get_user_settings(container, &settings); |
| 2713 | | |
| 2746 | //FIXME: Intended behaviour |
| 2747 | #if 1 |
| 2714 | 2748 | vid_attributes[0] = options_get_float(mame_options(), OPTION_GAMMA); |
| 2715 | 2749 | vid_attributes[1] = options_get_float(mame_options(), OPTION_CONTRAST); |
| 2716 | 2750 | vid_attributes[2] = options_get_float(mame_options(), OPTION_BRIGHTNESS); |
| 2751 | #else |
| 2752 | vid_attributes[0] = settings.gamma; |
| 2753 | vid_attributes[1] = settings.contrast; |
| 2754 | vid_attributes[2] = settings.brightness; |
| 2755 | #endif |
| 2717 | 2756 | vid_attributes[3] = 0.0f; |
| 2718 | 2757 | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[shaderIdx], "vid_attributes"); |
| 2719 | 2758 | pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx])); |
src/osd/sdl/input.c
| r2988 | r2989 | |
| 135 | 135 | |
| 136 | 136 | #if SDLMAME_EVENTS_IN_WORKER_THREAD |
| 137 | 137 | // input buffer |
| 138 | | #define MAX_BUF_EVENTS (100) |
| 138 | #define MAX_BUF_EVENTS (500) /* 100 not enough for SDL 1.3 */ |
| 139 | 139 | static SDL_Event event_buf[MAX_BUF_EVENTS]; |
| 140 | 140 | static int event_buf_count; |
| 141 | 141 | #endif |
| r2988 | r2989 | |
| 203 | 203 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 204 | 204 | |
| 205 | 205 | #define OSD_SDL_INDEX(x) (x) |
| 206 | #define OSD_SDL_INDEX_KEYSYM(keysym) ((keysym)->scancode) |
| 207 | #define GET_WINDOW(ev) window_from_id((ev)->windowID) |
| 206 | 208 | |
| 207 | 209 | #define KTT_ENTRY0(MAME, SDL, VK, AS, UI) { ITEM_ID_ ## MAME, SDL_SCANCODE_ ## SDL, "ITEM_ID_" #MAME, (char *) UI } |
| 208 | 210 | #define KTT_ENTRY1(MAME, SDL) KTT_ENTRY0(MAME, SDL, MAME, MAME, #MAME) |
| r2988 | r2989 | |
| 325 | 327 | #else |
| 326 | 328 | |
| 327 | 329 | #define OSD_SDL_INDEX(x) (SDLK_INDEX(x)-SDLK_FIRST) |
| 330 | #define OSD_SDL_INDEX_KEYSYM(keysym) (OSD_SDL_INDEX((keysym)->sym)) |
| 331 | #define GET_WINDOW(ev) sdl_window_list |
| 328 | 332 | |
| 329 | 333 | #define KTT_ENTRY0(MAME, SDL, VK, AS, UI) { ITEM_ID_ ## MAME, SDLK_ ## SDL, "ITEM_ID_" #MAME, (char *) UI } |
| 330 | 334 | #define KTT_ENTRY1(MAME, SDL) KTT_ENTRY0(MAME, SDL, MAME, MAME, #MAME) |
| r2988 | r2989 | |
| 578 | 582 | //============================================================ |
| 579 | 583 | // INLINE FUNCTIONS |
| 580 | 584 | //============================================================ |
| 581 | | #if 0 |
| 582 | | INLINE INT32 normalize_absolute_axis(INT32 raw, INT32 rawmin, INT32 rawmax) |
| 583 | | { |
| 584 | | INT32 center = (rawmax + rawmin) / 2; |
| 585 | 585 | |
| 586 | | // make sure we have valid data |
| 587 | | if (rawmin >= rawmax) |
| 588 | | return raw; |
| 589 | | |
| 590 | | // above center |
| 591 | | if (raw >= center) |
| 592 | | { |
| 593 | | INT32 result = (INT64)(raw - center) * (INT64)INPUT_ABSOLUTE_MAX / (INT64)(rawmax - center); |
| 594 | | return MIN(result, INPUT_ABSOLUTE_MAX); |
| 595 | | } |
| 596 | | |
| 597 | | // below center |
| 598 | | else |
| 599 | | { |
| 600 | | INT32 result = -((INT64)(center - raw) * (INT64)-INPUT_ABSOLUTE_MIN / (INT64)(center - rawmin)); |
| 601 | | return MAX(result, INPUT_ABSOLUTE_MIN); |
| 602 | | } |
| 603 | | } |
| 604 | | #endif |
| 605 | 586 | static int joy_map_leastfree(void) |
| 606 | 587 | { |
| 607 | 588 | int i; |
| r2988 | r2989 | |
| 888 | 869 | #endif |
| 889 | 870 | |
| 890 | 871 | //============================================================ |
| 872 | // sdlinput_read_keymap |
| 873 | //============================================================ |
| 874 | |
| 875 | static kt_table * sdlinput_read_keymap(char *keymap_filename) |
| 876 | { |
| 877 | kt_table *key_trans_table; |
| 878 | FILE *keymap_file; |
| 879 | int line = 1; |
| 880 | int index,i, sk, vk, ak; |
| 881 | char buf[256]; |
| 882 | char mks[21]; |
| 883 | char sks[21]; |
| 884 | char kns[21]; |
| 885 | |
| 886 | mame_printf_verbose("Keymap: Start reading keymap_file %s\n", keymap_filename); |
| 887 | |
| 888 | keymap_file = fopen(keymap_filename, "r"); |
| 889 | if (keymap_file == NULL) |
| 890 | { |
| 891 | mame_printf_warning( "Keymap: Unable to open keymap %s, using default\n", keymap_filename); |
| 892 | return sdl_key_trans_table; |
| 893 | } |
| 894 | |
| 895 | key_trans_table = auto_malloc(sizeof(sdl_key_trans_table)); |
| 896 | memcpy((void *) key_trans_table, sdl_key_trans_table, sizeof(sdl_key_trans_table)); |
| 897 | |
| 898 | while (!feof(keymap_file)) |
| 899 | { |
| 900 | fgets(buf, 255, keymap_file); |
| 901 | if (*buf && buf[0] && buf[0] != '#') |
| 902 | { |
| 903 | buf[255]=0; |
| 904 | i=strlen(buf); |
| 905 | if (i && buf[i-1] == '\n') |
| 906 | buf[i-1] = 0; |
| 907 | mks[0]=0; |
| 908 | sks[0]=0; |
| 909 | memset(kns, 0, 21); |
| 910 | sscanf(buf, "%20s %20s %x %x %20c\n", |
| 911 | mks, sks, &vk, &ak, kns); |
| 912 | |
| 913 | index=lookup_mame_index(mks); |
| 914 | sk = lookup_sdl_code(sks); |
| 915 | |
| 916 | if ( sk >= 0 && index >=0) |
| 917 | { |
| 918 | key_trans_table[index].sdl_key = sk; |
| 919 | // vk and ak are not really needed |
| 920 | //key_trans_table[index][VIRTUAL_KEY] = vk; |
| 921 | //key_trans_table[index][ASCII_KEY] = ak; |
| 922 | key_trans_table[index].ui_name = auto_malloc(strlen(kns)+1); |
| 923 | strcpy(key_trans_table[index].ui_name, kns); |
| 924 | mame_printf_verbose("Keymap: Mapped <%s> to <%s> with ui-text <%s>\n", sks, mks, kns); |
| 925 | } |
| 926 | else |
| 927 | mame_printf_warning("Keymap: Error on line %d - %s key not found: %s\n", line, (sk<0) ? "sdl" : "mame", buf); |
| 928 | } |
| 929 | line++; |
| 930 | } |
| 931 | fclose(keymap_file); |
| 932 | mame_printf_verbose("Keymap: Processed %d lines\n", line); |
| 933 | |
| 934 | return key_trans_table; |
| 935 | } |
| 936 | |
| 937 | //============================================================ |
| 891 | 938 | // sdlinput_init |
| 892 | 939 | //============================================================ |
| 893 | 940 | |
| r2988 | r2989 | |
| 897 | 944 | int keynum, button; |
| 898 | 945 | char defname[20]; |
| 899 | 946 | kt_table *key_trans_table; |
| 900 | | kt_table *ktt_alloc = NULL; |
| 901 | 947 | |
| 902 | | // we want unicode keyboard characters |
| 903 | | SDL_EnableUNICODE(1); |
| 904 | | |
| 905 | 948 | keyboard_list = NULL; |
| 906 | 949 | joystick_list = NULL; |
| 907 | 950 | mouse_list = NULL; |
| r2988 | r2989 | |
| 917 | 960 | if (options_get_bool(mame_options(), SDLOPTION_KEYMAP)) |
| 918 | 961 | { |
| 919 | 962 | char *keymap_filename; |
| 920 | | FILE *keymap_file; |
| 921 | | int line = 1; |
| 922 | 963 | |
| 923 | 964 | keymap_filename = (char *)options_get_string(mame_options(), SDLOPTION_KEYMAP_FILE); |
| 924 | | mame_printf_verbose("Keymap: Start reading keymap_file %s\n", keymap_filename); |
| 925 | 965 | |
| 926 | | keymap_file = fopen(keymap_filename, "r"); |
| 927 | | |
| 928 | | if (keymap_file == NULL) |
| 929 | | { |
| 930 | | mame_printf_warning( "Keymap: Unable to open keymap %s, using default\n", keymap_filename); |
| 931 | | key_trans_table = sdl_key_trans_table; |
| 932 | | } |
| 933 | | else |
| 934 | | { |
| 935 | | int index,i, sk, vk, ak; |
| 936 | | char buf[256]; |
| 937 | | char mks[21]; |
| 938 | | char sks[21]; |
| 939 | | char kns[21]; |
| 940 | | |
| 941 | | ktt_alloc = malloc_or_die(sizeof(sdl_key_trans_table)); |
| 942 | | key_trans_table = ktt_alloc; |
| 943 | | memcpy((void *) key_trans_table, sdl_key_trans_table, sizeof(sdl_key_trans_table)); |
| 944 | | while (!feof(keymap_file)) |
| 945 | | { |
| 946 | | fgets(buf, 255, keymap_file); |
| 947 | | if (*buf && buf[0] && buf[0] != '#') |
| 948 | | { |
| 949 | | buf[255]=0; |
| 950 | | i=strlen(buf); |
| 951 | | if (i && buf[i-1] == '\n') |
| 952 | | buf[i-1] = 0; |
| 953 | | mks[0]=0; |
| 954 | | sks[0]=0; |
| 955 | | memset(kns, 0, 21); |
| 956 | | sscanf(buf, "%20s %20s %x %x %20c\n", |
| 957 | | mks, sks, &vk, &ak, kns); |
| 958 | | |
| 959 | | index=lookup_mame_index(mks); |
| 960 | | sk = lookup_sdl_code(sks); |
| 961 | | |
| 962 | | if ( sk >= 0 && index >=0) |
| 963 | | { |
| 964 | | key_trans_table[index].sdl_key = sk; |
| 965 | | // vk and ak are not really needed |
| 966 | | //key_trans_table[index][VIRTUAL_KEY] = vk; |
| 967 | | //key_trans_table[index][ASCII_KEY] = ak; |
| 968 | | key_trans_table[index].ui_name = auto_malloc(strlen(kns)+1); |
| 969 | | strcpy(key_trans_table[index].ui_name, kns); |
| 970 | | mame_printf_verbose("Keymap: Mapped <%s> to <%s> with ui-text <%s>\n", sks, mks, kns); |
| 971 | | } |
| 972 | | else |
| 973 | | mame_printf_warning("Keymap: Error on line %d - %s key not found: %s\n", line, (sk<0) ? "sdl" : "mame", buf); |
| 974 | | } |
| 975 | | line++; |
| 976 | | } |
| 977 | | fclose(keymap_file); |
| 978 | | mame_printf_verbose("Keymap: Processed %d lines\n", line); |
| 979 | | } |
| 966 | key_trans_table = sdlinput_read_keymap(keymap_filename); |
| 980 | 967 | } |
| 981 | 968 | else |
| 982 | 969 | { |
| r2988 | r2989 | |
| 1030 | 1017 | device_list_reset_devices(mouse_list); |
| 1031 | 1018 | device_list_reset_devices(joystick_list); |
| 1032 | 1019 | |
| 1033 | | // clean up |
| 1034 | | if (ktt_alloc) |
| 1035 | | free(ktt_alloc); |
| 1036 | 1020 | } |
| 1037 | 1021 | |
| 1038 | 1022 | |
| r2988 | r2989 | |
| 1091 | 1075 | return w; |
| 1092 | 1076 | } |
| 1093 | 1077 | } |
| 1094 | | // deliberately crash |
| 1095 | | printf("Window %d not found\n", windowID); |
| 1096 | 1078 | return NULL; |
| 1097 | 1079 | } |
| 1098 | 1080 | #endif |
| r2988 | r2989 | |
| 1170 | 1152 | } |
| 1171 | 1153 | #endif |
| 1172 | 1154 | |
| 1173 | | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1174 | | ui_input_push_char_event(machine, window_from_id(event.window.windowID)->target, (unicode_char)event.key.keysym.unicode); |
| 1175 | | #else |
| 1176 | | ui_input_push_char_event(machine, sdl_window_list->target, (unicode_char)event.key.keysym.unicode); |
| 1177 | | #endif |
| 1178 | | |
| 1179 | 1155 | devinfo = keyboard_list; |
| 1180 | | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1181 | | devinfo->keyboard.state[OSD_SDL_INDEX(event.key.keysym.scancode)] = 0x80; |
| 1182 | | #else |
| 1183 | | devinfo->keyboard.state[OSD_SDL_INDEX(event.key.keysym.sym)] = 0x80; |
| 1156 | devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x80; |
| 1157 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 1158 | ui_input_push_char_event(machine, sdl_window_list->target, (unicode_char) event.key.keysym.unicode); |
| 1184 | 1159 | #endif |
| 1185 | 1160 | break; |
| 1186 | 1161 | case SDL_KEYUP: |
| 1187 | 1162 | devinfo = keyboard_list; |
| 1188 | | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1189 | | devinfo->keyboard.state[OSD_SDL_INDEX(event.key.keysym.scancode)] = 0x0; |
| 1190 | | #else |
| 1191 | | devinfo->keyboard.state[OSD_SDL_INDEX(event.key.keysym.sym)] = 0x0; |
| 1192 | | #endif |
| 1163 | devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x00; |
| 1193 | 1164 | break; |
| 1194 | 1165 | case SDL_JOYAXISMOTION: |
| 1195 | 1166 | devinfo = generic_device_find_index(joystick_list, joy_logical[event.jaxis.which]); |
| r2988 | r2989 | |
| 1263 | 1234 | case SDL_MOUSEBUTTONDOWN: |
| 1264 | 1235 | devinfo = mouse_list; |
| 1265 | 1236 | devinfo->mouse.buttons[event.button.button-1] = 0x80; |
| 1266 | | |
| 1267 | | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1268 | | ui_input_push_mouse_click_event(machine, window_from_id(event.window.windowID)->target, event.button.x, event.button.y); |
| 1269 | | #else |
| 1270 | | ui_input_push_mouse_click_event(machine, sdl_window_list->target, event.button.x, event.button.y); |
| 1271 | | #endif |
| 1272 | | |
| 1237 | if (event.button.button == 1) |
| 1238 | { |
| 1239 | // FIXME Move static declaration |
| 1240 | static osd_ticks_t last_click = 0; |
| 1241 | static int last_x = 0; |
| 1242 | static int last_y = 0; |
| 1243 | int cx, cy; |
| 1244 | osd_ticks_t click = osd_ticks() * 1000 / osd_ticks_per_second(); |
| 1245 | sdl_window_info *window = GET_WINDOW(&event.button); |
| 1246 | |
| 1247 | if (window != NULL && window->xy_to_render_target(window, event.button.x,event.button.y, &cx, &cy) ) |
| 1248 | { |
| 1249 | ui_input_push_mouse_click_event(machine, window->target, cx, cy); |
| 1250 | // FIXME Parameter ? |
| 1251 | if ((click-last_click < 250) |
| 1252 | && (cx >= last_x - 4 && cx <= last_x + 4) |
| 1253 | && (cy >= last_y - 4 && cy <= last_y + 4) ) |
| 1254 | { |
| 1255 | last_click = 0; |
| 1256 | ui_input_push_mouse_double_click_event(machine, window->target, cx, cy); |
| 1257 | } |
| 1258 | else |
| 1259 | { |
| 1260 | last_click = click; |
| 1261 | last_x = cx; |
| 1262 | last_y = cy; |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1273 | 1266 | break; |
| 1274 | 1267 | case SDL_MOUSEBUTTONUP: |
| 1275 | 1268 | devinfo = mouse_list; |
| r2988 | r2989 | |
| 1279 | 1272 | devinfo = mouse_list; |
| 1280 | 1273 | devinfo->mouse.lX = event.motion.xrel * INPUT_RELATIVE_PER_PIXEL; |
| 1281 | 1274 | devinfo->mouse.lY = event.motion.yrel * INPUT_RELATIVE_PER_PIXEL; |
| 1282 | | |
| 1283 | | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1284 | | ui_input_push_mouse_move_event(machine, window_from_id(event.window.windowID)->target, event.motion.xrel * INPUT_RELATIVE_PER_PIXEL, event.motion.yrel * INPUT_RELATIVE_PER_PIXEL); |
| 1285 | | #else |
| 1286 | | ui_input_push_mouse_move_event(machine, sdl_window_list->target, event.motion.xrel * INPUT_RELATIVE_PER_PIXEL, event.motion.yrel * INPUT_RELATIVE_PER_PIXEL); |
| 1287 | | #endif |
| 1275 | { |
| 1276 | int cx=-1, cy=-1; |
| 1277 | sdl_window_info *window = GET_WINDOW(&event.motion); |
| 1278 | |
| 1279 | if (window != NULL && window->xy_to_render_target(window, event.motion.x, event.motion.y, &cx, &cy) ) |
| 1280 | ui_input_push_mouse_move_event(machine, window->target, cx, cy); |
| 1281 | } |
| 1288 | 1282 | break; |
| 1289 | 1283 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 1290 | 1284 | case SDL_QUIT: |
| r2988 | r2989 | |
| 1294 | 1288 | sdlwindow_resize(sdl_window_list, event.resize.w, event.resize.h); |
| 1295 | 1289 | break; |
| 1296 | 1290 | #else |
| 1291 | case SDL_TEXTINPUT: |
| 1292 | if (*event.text.text) |
| 1293 | { |
| 1294 | sdl_window_info *w = GET_WINDOW(&event.text); |
| 1295 | unicode_char result; |
| 1296 | osd_uchar_from_osdchar(&result, event.text.text, 1); |
| 1297 | ui_input_push_char_event(machine, w->target, result); |
| 1298 | } |
| 1299 | break; |
| 1297 | 1300 | case SDL_WINDOWEVENT: |
| 1301 | { |
| 1302 | sdl_window_info *window = GET_WINDOW(&event.window); |
| 1303 | |
| 1304 | if (window == NULL) |
| 1305 | break; |
| 1306 | |
| 1298 | 1307 | switch (event.window.event) |
| 1299 | 1308 | { |
| 1300 | 1309 | case SDL_WINDOWEVENT_CLOSE: |
| 1301 | 1310 | mame_schedule_exit(machine); |
| 1302 | 1311 | break; |
| 1312 | case SDL_WINDOWEVENT_LEAVE: |
| 1313 | { |
| 1314 | ui_input_push_mouse_leave_event(machine, window->target); |
| 1315 | break; |
| 1316 | |
| 1317 | } |
| 1303 | 1318 | case SDL_WINDOWEVENT_RESIZED: |
| 1304 | | sdlwindow_resize(window_from_id(event.window.windowID), event.window.data1, event.window.data2); |
| 1319 | sdlwindow_resize(window, event.window.data1, event.window.data2); |
| 1305 | 1320 | /* fall through break; */ |
| 1306 | 1321 | case SDL_WINDOWEVENT_FOCUS_GAINED: |
| 1307 | 1322 | case SDL_WINDOWEVENT_ENTER: |
| 1308 | 1323 | case SDL_WINDOWEVENT_EXPOSED: |
| 1309 | 1324 | case SDL_WINDOWEVENT_MAXIMIZED: |
| 1310 | 1325 | case SDL_WINDOWEVENT_RESTORED: |
| 1311 | | focus_window = window_from_id(event.window.windowID); |
| 1326 | focus_window = window; |
| 1312 | 1327 | break; |
| 1313 | 1328 | } |
| 1314 | 1329 | break; |
| 1330 | } |
| 1315 | 1331 | #endif |
| 1316 | 1332 | } |
| 1317 | 1333 | } |
src/osd/sdl/drawsdl.c
| r2988 | r2989 | |
| 48 | 48 | struct _sdl_info |
| 49 | 49 | { |
| 50 | 50 | INT32 blittimer; |
| 51 | UINT32 extra_flags; |
| 51 | 52 | |
| 52 | 53 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 53 | 54 | SDL_TextureID texture_id; |
| r2988 | r2989 | |
| 60 | 61 | // YUV overlay |
| 61 | 62 | UINT32 *yuv_lookup; |
| 62 | 63 | UINT16 *yuv_bitmap; |
| 63 | | int yuv_ovl_width; |
| 64 | | int yuv_ovl_height; |
| 64 | |
| 65 | // if we leave scaling to SDL and the underlying driver, this |
| 66 | // is the render_target_width/height to use |
| 67 | |
| 68 | int hw_scale_width; |
| 69 | int hw_scale_height; |
| 70 | int last_hofs; |
| 71 | int last_vofs; |
| 65 | 72 | }; |
| 66 | 73 | |
| 67 | 74 | //============================================================ |
| r2988 | r2989 | |
| 74 | 81 | |
| 75 | 82 | // core functions |
| 76 | 83 | static void drawsdl_exit(void); |
| 84 | static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window); |
| 77 | 85 | static int drawsdl_window_create(sdl_window_info *window, int width, int height); |
| 78 | 86 | static void drawsdl_window_resize(sdl_window_info *window, int width, int height); |
| 79 | 87 | static void drawsdl_window_destroy(sdl_window_info *window); |
| r2988 | r2989 | |
| 81 | 89 | static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 82 | 90 | static void drawsdl_destroy_all_textures(sdl_window_info *window); |
| 83 | 91 | static void drawsdl_window_clear(sdl_window_info *window); |
| 92 | static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 93 | |
| 84 | 94 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 85 | 95 | static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight); |
| 86 | 96 | #endif |
| r2988 | r2989 | |
| 103 | 113 | |
| 104 | 114 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 105 | 115 | static int shown_video_info = 0; |
| 106 | | static const char *yuv_mode_names[] = { "none", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 116 | static const char *scale_mode_names[] = { "none", "hwblit", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 107 | 117 | #endif |
| 108 | 118 | |
| 109 | 119 | //============================================================ |
| 110 | 120 | // drawsdl_init |
| 111 | 121 | //============================================================ |
| 112 | 122 | |
| 113 | | int drawsdl_init(sdl_draw_callbacks *callbacks) |
| 123 | int drawsdl_init(sdl_draw_info *callbacks) |
| 114 | 124 | { |
| 115 | 125 | // fill in the callbacks |
| 116 | 126 | callbacks->exit = drawsdl_exit; |
| 117 | | callbacks->window_create = drawsdl_window_create; |
| 118 | | callbacks->window_resize = drawsdl_window_resize; |
| 119 | | callbacks->window_get_primitives = drawsdl_window_get_primitives; |
| 120 | | callbacks->window_draw = drawsdl_window_draw; |
| 121 | | callbacks->window_destroy = drawsdl_window_destroy; |
| 122 | | callbacks->window_destroy_all_textures = drawsdl_destroy_all_textures; |
| 123 | | callbacks->window_clear = drawsdl_window_clear; |
| 127 | callbacks->attach = drawsdl_attach; |
| 124 | 128 | |
| 125 | | #if SDL_VERSION_ATLEAST(1,3,0) |
| 126 | | mame_printf_verbose("Using SDL multi-window soft driver (SDL 1.3+)\n"); |
| 127 | | #else |
| 128 | | mame_printf_verbose("Using SDL single-window soft driver (SDL 1.2)\n"); |
| 129 | | #endif |
| 129 | if (SDL_VERSION_ATLEAST(1,3,0)) |
| 130 | mame_printf_verbose("Using SDL multi-window soft driver (SDL 1.3+)\n"); |
| 131 | else |
| 132 | mame_printf_verbose("Using SDL single-window soft driver (SDL 1.2)\n"); |
| 133 | |
| 130 | 134 | return 0; |
| 131 | 135 | } |
| 132 | 136 | |
| r2988 | r2989 | |
| 139 | 143 | } |
| 140 | 144 | |
| 141 | 145 | //============================================================ |
| 146 | // drawsdl_attach |
| 147 | //============================================================ |
| 148 | |
| 149 | static void drawsdl_attach(sdl_draw_info *info, sdl_window_info *window) |
| 150 | { |
| 151 | // fill in the callbacks |
| 152 | window->create = drawsdl_window_create; |
| 153 | window->resize = drawsdl_window_resize; |
| 154 | window->get_primitives = drawsdl_window_get_primitives; |
| 155 | window->draw = drawsdl_window_draw; |
| 156 | window->destroy = drawsdl_window_destroy; |
| 157 | window->destroy_all_textures = drawsdl_destroy_all_textures; |
| 158 | window->clear = drawsdl_window_clear; |
| 159 | window->xy_to_render_target = drawsdl_xy_to_render_target; |
| 160 | } |
| 161 | |
| 162 | //============================================================ |
| 142 | 163 | // drawsdl_destroy_all_textures |
| 143 | 164 | //============================================================ |
| 144 | 165 | |
| r2988 | r2989 | |
| 155 | 176 | static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight) |
| 156 | 177 | { |
| 157 | 178 | sdl_info * sdl = window->dxdata; |
| 179 | SDL_DisplayMode mode; |
| 180 | |
| 158 | 181 | // Determine preferred pixelformat and set up yuv if necessary |
| 182 | SDL_GetCurrentDisplayMode(&mode); |
| 159 | 183 | |
| 160 | 184 | if (sdl->yuv_bitmap) |
| 161 | 185 | { |
| r2988 | r2989 | |
| 163 | 187 | sdl->yuv_bitmap = NULL; |
| 164 | 188 | } |
| 165 | 189 | |
| 166 | | switch (video_config.yuv_mode) |
| 190 | switch (window->scale_mode) |
| 167 | 191 | { |
| 168 | | case VIDEO_YUV_MODE_NONE: |
| 169 | | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, |
| 192 | case VIDEO_SCALE_MODE_NONE: |
| 193 | sdl->texture_id = SDL_CreateTexture(mode.format, SDL_TEXTUREACCESS_STREAMING, |
| 170 | 194 | tempwidth, tempheight); |
| 171 | 195 | SDL_SetTextureScaleMode(sdl->texture_id, SDL_TEXTURESCALEMODE_NONE); |
| 172 | 196 | break; |
| 173 | | case VIDEO_YUV_MODE_YV12: |
| 174 | | render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height); |
| 175 | | sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16)); |
| 197 | case VIDEO_SCALE_MODE_HWBLIT: |
| 198 | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 199 | sdl->texture_id = SDL_CreateTexture(mode.format, SDL_TEXTUREACCESS_STREAMING, |
| 200 | sdl->hw_scale_width, sdl->hw_scale_height); |
| 201 | break; |
| 202 | case VIDEO_SCALE_MODE_YV12: |
| 203 | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 204 | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 176 | 205 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, |
| 177 | | sdl->yuv_ovl_width, sdl->yuv_ovl_height); |
| 178 | | //SDL_SetTextureScaleMode(sdl->sdltex, SDL_TEXTURESCALEMODE_FAST); |
| 206 | sdl->hw_scale_width, sdl->hw_scale_height); |
| 179 | 207 | break; |
| 180 | | case VIDEO_YUV_MODE_YV12X2: |
| 181 | | render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height); |
| 182 | | sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16)); |
| 208 | case VIDEO_SCALE_MODE_YV12X2: |
| 209 | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 210 | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 183 | 211 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, |
| 184 | | sdl->yuv_ovl_width * 2, sdl->yuv_ovl_height * 2); |
| 212 | sdl->hw_scale_width * 2, sdl->hw_scale_height * 2); |
| 185 | 213 | break; |
| 186 | | case VIDEO_YUV_MODE_YUY2: |
| 187 | | render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height); |
| 188 | | sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16)); |
| 214 | case VIDEO_SCALE_MODE_YUY2: |
| 215 | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 216 | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 189 | 217 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, |
| 190 | | sdl->yuv_ovl_width, sdl->yuv_ovl_height); |
| 218 | sdl->hw_scale_width, sdl->hw_scale_height); |
| 191 | 219 | break; |
| 192 | | case VIDEO_YUV_MODE_YUY2X2: |
| 193 | | render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height); |
| 194 | | sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16)); |
| 220 | case VIDEO_SCALE_MODE_YUY2X2: |
| 221 | render_target_get_minimum_size(window->target, &sdl->hw_scale_width, &sdl->hw_scale_height); |
| 222 | sdl->yuv_bitmap = malloc_or_die(sdl->hw_scale_width * sdl->hw_scale_height * sizeof(UINT16)); |
| 195 | 223 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, |
| 196 | | sdl->yuv_ovl_width * 2, sdl->yuv_ovl_height); |
| 224 | sdl->hw_scale_width * 2, sdl->hw_scale_height); |
| 197 | 225 | break; |
| 198 | 226 | } |
| 199 | 227 | } |
| r2988 | r2989 | |
| 211 | 239 | |
| 212 | 240 | render_target_get_minimum_size(window->target, &minimum_width, &minimum_height); |
| 213 | 241 | if (sdl->yuvsurf != NULL) |
| 242 | { |
| 214 | 243 | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| 244 | sdl->yuvsurf = NULL; |
| 245 | } |
| 246 | |
| 215 | 247 | if (sdl->yuv_bitmap != NULL) |
| 216 | 248 | { |
| 217 | 249 | free(sdl->yuv_bitmap); |
| 218 | 250 | } |
| 219 | 251 | sdl->yuv_bitmap = malloc_or_die(minimum_width*minimum_height*sizeof(UINT16)); |
| 220 | 252 | |
| 221 | | mame_printf_verbose("SDL: Creating YUV-Overlay ...\n"); |
| 222 | | switch (video_config.yuv_mode) |
| 253 | mame_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height); |
| 254 | switch (window->scale_mode) |
| 223 | 255 | { |
| 224 | | case VIDEO_YUV_MODE_YV12: |
| 256 | case VIDEO_SCALE_MODE_YV12: |
| 225 | 257 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 226 | 258 | SDL_YV12_OVERLAY, sdl->sdlsurf); |
| 227 | 259 | break; |
| 228 | | case VIDEO_YUV_MODE_YV12X2: |
| 260 | case VIDEO_SCALE_MODE_YV12X2: |
| 229 | 261 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height*2, |
| 230 | 262 | SDL_YV12_OVERLAY, sdl->sdlsurf); |
| 231 | 263 | break; |
| 232 | | case VIDEO_YUV_MODE_YUY2: |
| 264 | case VIDEO_SCALE_MODE_YUY2: |
| 233 | 265 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 234 | 266 | SDL_YUY2_OVERLAY, sdl->sdlsurf); |
| 235 | 267 | break; |
| 236 | | case VIDEO_YUV_MODE_YUY2X2: |
| 268 | case VIDEO_SCALE_MODE_YUY2X2: |
| 237 | 269 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height, |
| 238 | 270 | SDL_YUY2_OVERLAY, sdl->sdlsurf); |
| 239 | 271 | break; |
| r2988 | r2989 | |
| 242 | 274 | mame_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); |
| 243 | 275 | //return 1; |
| 244 | 276 | } |
| 245 | | sdl->yuv_ovl_width = minimum_width; |
| 246 | | sdl->yuv_ovl_height = minimum_height; |
| 277 | sdl->hw_scale_width = minimum_width; |
| 278 | sdl->hw_scale_height = minimum_height; |
| 247 | 279 | |
| 248 | 280 | if (!shown_video_info) |
| 249 | 281 | { |
| 250 | | mame_printf_verbose("YUV Mode : %s\n", yuv_mode_names[video_config.yuv_mode]); |
| 282 | mame_printf_verbose("YUV Mode : %s\n", scale_mode_names[window->scale_mode]); |
| 251 | 283 | mame_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height); |
| 252 | 284 | mame_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software"); |
| 253 | 285 | shown_video_info = 1; |
| r2988 | r2989 | |
| 270 | 302 | window->dxdata = sdl; |
| 271 | 303 | |
| 272 | 304 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 273 | | window->extra_flags = (window->fullscreen ? |
| 305 | sdl->extra_flags = (window->fullscreen ? |
| 274 | 306 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE); |
| 275 | | //FIXME: OpenGL in Software |
| 276 | | /* the following is a workaround for a bug in SDL 1.3 |
| 277 | | * where creating a renderer will loose keyboard focus |
| 278 | | * This happens only if one window is present. |
| 279 | | */ |
| 280 | | window->extra_flags |= SDL_WINDOW_OPENGL; |
| 281 | 307 | |
| 282 | 308 | SDL_SelectVideoDisplay(window->monitor->handle); |
| 283 | | SDL_SetFullscreenDisplayMode(NULL); // Use desktop |
| 309 | |
| 310 | if (window->fullscreen && video_config.switchres) |
| 311 | { |
| 312 | SDL_DisplayMode mode; |
| 313 | SDL_GetCurrentDisplayMode(&mode); |
| 314 | mode.w = width; |
| 315 | mode.h = height; |
| 316 | SDL_SetFullscreenDisplayMode(&mode); // Try to set mode |
| 317 | } |
| 318 | else |
| 319 | SDL_SetFullscreenDisplayMode(NULL); // Use desktop |
| 320 | |
| 284 | 321 | window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 285 | | width, height, window->extra_flags); |
| 322 | width, height, sdl->extra_flags); |
| 286 | 323 | SDL_ShowWindow(window->window_id); |
| 287 | | SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 288 | 324 | SDL_RaiseWindow(window->window_id); |
| 289 | | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 290 | 325 | |
| 291 | 326 | // create a texture |
| 292 | 327 | SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD); |
| 293 | 328 | SDL_SelectRenderer(window->window_id); |
| 329 | SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 330 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 294 | 331 | setup_texture(window, width, height); |
| 295 | 332 | #else |
| 296 | | window->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 333 | sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 297 | 334 | // create the SDL surface (which creates the window in windowed mode) |
| 298 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 299 | | window->extra_flags |= SDL_DOUBLEBUF; |
| 335 | if (!IS_YUV_MODE(window->scale_mode)) |
| 336 | sdl->extra_flags |= SDL_DOUBLEBUF; |
| 300 | 337 | |
| 301 | 338 | sdl->sdlsurf = SDL_SetVideoMode(width, height, |
| 302 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 339 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 303 | 340 | |
| 304 | 341 | if (!sdl->sdlsurf) |
| 305 | 342 | return 1; |
| r2988 | r2989 | |
| 307 | 344 | window->width = sdl->sdlsurf->w; |
| 308 | 345 | window->height = sdl->sdlsurf->h; |
| 309 | 346 | |
| 310 | | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 347 | if (IS_YUV_MODE(window->scale_mode)) |
| 311 | 348 | { |
| 312 | 349 | yuv_overlay_init(window); |
| 313 | 350 | } |
| r2988 | r2989 | |
| 340 | 377 | |
| 341 | 378 | setup_texture(window, window->width, window->height); |
| 342 | 379 | #else |
| 380 | if (sdl->yuvsurf != NULL) |
| 381 | { |
| 382 | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| 383 | sdl->yuvsurf = NULL; |
| 384 | } |
| 343 | 385 | SDL_FreeSurface(sdl->sdlsurf); |
| 344 | 386 | //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height); |
| 345 | 387 | |
| 346 | 388 | sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 347 | | SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 389 | SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); |
| 348 | 390 | window->width = sdl->sdlsurf->w; |
| 349 | 391 | window->height = sdl->sdlsurf->h; |
| 350 | 392 | |
| 351 | | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 393 | if (IS_YUV_MODE(window->scale_mode)) |
| 352 | 394 | { |
| 353 | 395 | yuv_overlay_init(window); |
| 354 | 396 | } |
| r2988 | r2989 | |
| 375 | 417 | //SDL_DestroyRenderer(window->window_id); |
| 376 | 418 | SDL_DestroyWindow(window->window_id); |
| 377 | 419 | #else |
| 420 | if (sdl->yuvsurf != NULL) |
| 421 | { |
| 422 | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| 423 | sdl->yuvsurf = NULL; |
| 424 | } |
| 425 | |
| 378 | 426 | if (sdl->sdlsurf) |
| 379 | 427 | { |
| 380 | 428 | SDL_FreeSurface(sdl->sdlsurf); |
| r2988 | r2989 | |
| 409 | 457 | } |
| 410 | 458 | |
| 411 | 459 | //============================================================ |
| 460 | // drawsdl_xy_to_render_target |
| 461 | //============================================================ |
| 462 | |
| 463 | static int drawsdl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 464 | { |
| 465 | sdl_info *sdl = window->dxdata; |
| 466 | |
| 467 | *xt = x - sdl->last_hofs; |
| 468 | *yt = y - sdl->last_vofs; |
| 469 | if (*xt<0 || *xt >= window->blitwidth) |
| 470 | return 0; |
| 471 | if (*yt<0 || *xt >= window->blitheight) |
| 472 | return 0; |
| 473 | if (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode))) |
| 474 | { |
| 475 | return 1; |
| 476 | } |
| 477 | /* Rescale */ |
| 478 | *xt = (*xt * sdl->hw_scale_width) / window->blitwidth; |
| 479 | *yt = (*yt * sdl->hw_scale_height) / window->blitheight; |
| 480 | return 1; |
| 481 | } |
| 482 | |
| 483 | //============================================================ |
| 412 | 484 | // drawsdl_window_get_primitives |
| 413 | 485 | //============================================================ |
| 414 | 486 | |
| r2988 | r2989 | |
| 423 | 495 | { |
| 424 | 496 | sdlwindow_blit_surface_size(window, window->monitor->center_width, window->monitor->center_height); |
| 425 | 497 | } |
| 426 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 498 | if (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode))) |
| 427 | 499 | render_target_set_bounds(window->target, window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor)); |
| 428 | 500 | else |
| 429 | | render_target_set_bounds(window->target, sdl->yuv_ovl_width, sdl->yuv_ovl_height, 0); |
| 501 | render_target_set_bounds(window->target, sdl->hw_scale_width, sdl->hw_scale_height, 0); |
| 430 | 502 | return render_target_get_primitives(window->target); |
| 431 | 503 | } |
| 432 | 504 | |
| r2988 | r2989 | |
| 472 | 544 | } |
| 473 | 545 | |
| 474 | 546 | |
| 475 | | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 547 | if (IS_YUV_MODE(window->scale_mode)) |
| 476 | 548 | { |
| 477 | 549 | SDL_LockYUVOverlay(sdl->yuvsurf); |
| 478 | 550 | surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->yuv_bitmap; |
| r2988 | r2989 | |
| 493 | 565 | |
| 494 | 566 | SDL_LockTexture(sdl->texture_id, NULL, 1, (void **) &surfptr, &pitch); |
| 495 | 567 | // Clear if necessary |
| 496 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 568 | if (window->scale_mode == VIDEO_SCALE_MODE_NONE) |
| 497 | 569 | if (sdl->blittimer > 0) |
| 498 | 570 | { |
| 499 | 571 | memset(surfptr, 0, window->height * pitch); |
| r2988 | r2989 | |
| 539 | 611 | hofs = (cw - window->blitwidth) / 2; |
| 540 | 612 | } |
| 541 | 613 | |
| 614 | sdl->last_hofs = hofs; |
| 615 | sdl->last_vofs = vofs; |
| 616 | |
| 542 | 617 | osd_lock_acquire(window->primlist->lock); |
| 543 | 618 | |
| 544 | 619 | // render to it |
| 545 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 620 | if (!IS_YUV_MODE(window->scale_mode)) |
| 546 | 621 | { |
| 547 | | surfptr += ((vofs * pitch) + (hofs * bpp)); |
| 622 | int mamewidth, mameheight; |
| 623 | |
| 624 | if (window->scale_mode == VIDEO_SCALE_MODE_NONE || !SDL_VERSION_ATLEAST(1,3,0)) |
| 625 | { |
| 626 | mamewidth = blitwidth; |
| 627 | mameheight = blitheight; |
| 628 | surfptr += ((vofs * pitch) + (hofs * bpp)); |
| 629 | } |
| 630 | else |
| 631 | { |
| 632 | mamewidth = sdl->hw_scale_width; |
| 633 | mameheight = sdl->hw_scale_height; |
| 634 | } |
| 548 | 635 | switch (rmask) |
| 549 | 636 | { |
| 550 | 637 | case 0x00ff0000: |
| 551 | | drawsdl_rgb888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 4); |
| 638 | drawsdl_rgb888_draw_primitives(window->primlist->head, surfptr, mamewidth, mameheight, pitch / 4); |
| 552 | 639 | break; |
| 553 | 640 | |
| 554 | 641 | case 0x000000ff: |
| 555 | | drawsdl_bgr888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 4); |
| 642 | drawsdl_bgr888_draw_primitives(window->primlist->head, surfptr, mamewidth, mameheight, pitch / 4); |
| 556 | 643 | break; |
| 557 | 644 | |
| 558 | 645 | case 0xf800: |
| 559 | | drawsdl_rgb565_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 2); |
| 646 | drawsdl_rgb565_draw_primitives(window->primlist->head, surfptr, mamewidth, mameheight, pitch / 2); |
| 560 | 647 | break; |
| 561 | 648 | |
| 562 | 649 | case 0x7c00: |
| 563 | | drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 2); |
| 650 | drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, mamewidth, mameheight, pitch / 2); |
| 564 | 651 | break; |
| 565 | 652 | |
| 566 | 653 | default: |
| r2988 | r2989 | |
| 572 | 659 | { |
| 573 | 660 | assert (sdl->yuv_bitmap != NULL); |
| 574 | 661 | assert (surfptr != NULL); |
| 575 | | drawsdl_rgb555_draw_primitives(window->primlist->head, sdl->yuv_bitmap, sdl->yuv_ovl_width, sdl->yuv_ovl_height, sdl->yuv_ovl_width); |
| 576 | | switch (video_config.yuv_mode) |
| 662 | drawsdl_rgb555_draw_primitives(window->primlist->head, sdl->yuv_bitmap, sdl->hw_scale_width, sdl->hw_scale_height, sdl->hw_scale_width); |
| 663 | switch (window->scale_mode) |
| 577 | 664 | { |
| 578 | | case VIDEO_YUV_MODE_YV12: |
| 665 | case VIDEO_SCALE_MODE_YV12: |
| 579 | 666 | yuv_RGB_to_YV12((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 580 | 667 | break; |
| 581 | | case VIDEO_YUV_MODE_YV12X2: |
| 668 | case VIDEO_SCALE_MODE_YV12X2: |
| 582 | 669 | yuv_RGB_to_YV12X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 583 | 670 | break; |
| 584 | | case VIDEO_YUV_MODE_YUY2: |
| 671 | case VIDEO_SCALE_MODE_YUY2: |
| 585 | 672 | yuv_RGB_to_YUY2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 586 | 673 | break; |
| 587 | | case VIDEO_YUV_MODE_YUY2X2: |
| 674 | case VIDEO_SCALE_MODE_YUY2X2: |
| 588 | 675 | yuv_RGB_to_YUY2X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 589 | 676 | break; |
| 590 | 677 | } |
| r2988 | r2989 | |
| 595 | 682 | // unlock and flip |
| 596 | 683 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 597 | 684 | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf); |
| 598 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 685 | if (!IS_YUV_MODE(window->scale_mode)) |
| 599 | 686 | { |
| 600 | 687 | SDL_Flip(sdl->sdlsurf); |
| 601 | 688 | } |
| r2988 | r2989 | |
| 612 | 699 | } |
| 613 | 700 | #else |
| 614 | 701 | SDL_UnlockTexture(sdl->texture_id); |
| 615 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 702 | if (window->scale_mode == VIDEO_SCALE_MODE_NONE) |
| 616 | 703 | { |
| 617 | 704 | //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); |
| 618 | 705 | SDL_RenderCopy(sdl->texture_id, NULL, NULL); |
| r2988 | r2989 | |
| 764 | 851 | int u1,v1,y1,u2,v2,y2,u3,v3,y3,u4,v4,y4; /* 12 */ |
| 765 | 852 | |
| 766 | 853 | pixels[0] = ptr; |
| 767 | | pixels[1] = ptr + pitch * sdl->yuv_ovl_height; |
| 768 | | pixels[2] = pixels[1] + pitch * sdl->yuv_ovl_height / 4; |
| 854 | pixels[1] = ptr + pitch * sdl->hw_scale_height; |
| 855 | pixels[2] = pixels[1] + pitch * sdl->hw_scale_height / 4; |
| 769 | 856 | |
| 770 | | for(y=0;y<sdl->yuv_ovl_height;y+=2) |
| 857 | for(y=0;y<sdl->hw_scale_height;y+=2) |
| 771 | 858 | { |
| 772 | | src=bitmap + (y * sdl->yuv_ovl_width) ; |
| 773 | | src2=src + sdl->yuv_ovl_width; |
| 859 | src=bitmap + (y * sdl->hw_scale_width) ; |
| 860 | src2=src + sdl->hw_scale_width; |
| 774 | 861 | |
| 775 | 862 | dest_y = pixels[0] + y * pitch; |
| 776 | 863 | dest_v = pixels[1] + (y>>1) * pitch / 2; |
| 777 | 864 | dest_u = pixels[2] + (y>>1) * pitch / 2; |
| 778 | 865 | |
| 779 | | for(x=0;x<sdl->yuv_ovl_width;x+=2) |
| 866 | for(x=0;x<sdl->hw_scale_width;x+=2) |
| 780 | 867 | { |
| 781 | 868 | v1 = lookup[src[x]]; |
| 782 | 869 | y1 = (v1>>Y1SHIFT) & 0xff; |
| r2988 | r2989 | |
| 822 | 909 | UINT8 *pixels[3]; |
| 823 | 910 | |
| 824 | 911 | pixels[0] = ptr; |
| 825 | | pixels[1] = ptr + pitch * sdl->yuv_ovl_height * 2; |
| 826 | | pixels[2] = pixels[1] + pitch * sdl->yuv_ovl_height / 2; |
| 912 | pixels[1] = ptr + pitch * sdl->hw_scale_height * 2; |
| 913 | pixels[2] = pixels[1] + pitch * sdl->hw_scale_height / 2; |
| 827 | 914 | |
| 828 | | for(y=0;y<sdl->yuv_ovl_height;y++) |
| 915 | for(y=0;y<sdl->hw_scale_height;y++) |
| 829 | 916 | { |
| 830 | | src = bitmap + (y * sdl->yuv_ovl_width) ; |
| 917 | src = bitmap + (y * sdl->hw_scale_width) ; |
| 831 | 918 | |
| 832 | 919 | dest_y = (UINT16 *)(pixels[0] + 2 * y * pitch); |
| 833 | 920 | dest_v = pixels[1] + y * pitch / 2; |
| 834 | 921 | dest_u = pixels[2] + y * pitch / 2; |
| 835 | | for(x=0;x<sdl->yuv_ovl_width;x++) |
| 922 | for(x=0;x<sdl->hw_scale_width;x++) |
| 836 | 923 | { |
| 837 | 924 | v1 = sdl->yuv_lookup[src[x]]; |
| 838 | 925 | y1 = (v1 >> Y1SHIFT) & 0xff; |
| r2988 | r2989 | |
| 858 | 945 | UINT32 *lookup = sdl->yuv_lookup; |
| 859 | 946 | int yuv_pitch = pitch/4; |
| 860 | 947 | |
| 861 | | for(y=0;y<sdl->yuv_ovl_height;y++) |
| 948 | for(y=0;y<sdl->hw_scale_height;y++) |
| 862 | 949 | { |
| 863 | | src=bitmap + (y * sdl->yuv_ovl_width) ; |
| 864 | | end=src+sdl->yuv_ovl_width; |
| 950 | src=bitmap + (y * sdl->hw_scale_width) ; |
| 951 | end=src+sdl->hw_scale_width; |
| 865 | 952 | |
| 866 | 953 | dest = (UINT32 *) ptr; |
| 867 | 954 | dest += y * yuv_pitch; |
| r2988 | r2989 | |
| 886 | 973 | UINT32 *lookup = sdl->yuv_lookup; |
| 887 | 974 | int yuv_pitch = pitch / 4; |
| 888 | 975 | |
| 889 | | for(y=0;y<sdl->yuv_ovl_height;y++) |
| 976 | for(y=0;y<sdl->hw_scale_height;y++) |
| 890 | 977 | { |
| 891 | | src=bitmap + (y * sdl->yuv_ovl_width) ; |
| 892 | | end=src+sdl->yuv_ovl_width; |
| 978 | src=bitmap + (y * sdl->hw_scale_width) ; |
| 979 | end=src+sdl->hw_scale_width; |
| 893 | 980 | |
| 894 | 981 | dest = (UINT32 *) ptr; |
| 895 | 982 | dest += (y * yuv_pitch); |
src/osd/sdl/video.c
| r2988 | r2989 | |
| 49 | 49 | #include "video.h" |
| 50 | 50 | #include "window.h" |
| 51 | 51 | #include "input.h" |
| 52 | #include "uiinput.h" |
| 52 | 53 | |
| 53 | 54 | #include "osdsdl.h" |
| 54 | 55 | |
| 55 | 56 | #include "osd_opengl.h" |
| 56 | 57 | |
| 57 | | #include "uiinput.h" |
| 58 | | |
| 59 | 58 | #ifdef MESS |
| 60 | 59 | #include "menu.h" |
| 61 | 60 | #endif |
| r2988 | r2989 | |
| 64 | 63 | // CONSTANTS |
| 65 | 64 | //============================================================ |
| 66 | 65 | |
| 67 | | // refresh rate while paused |
| 68 | | #define PAUSED_REFRESH_RATE (60) |
| 69 | 66 | |
| 70 | | |
| 71 | 67 | //============================================================ |
| 72 | 68 | // GLOBAL VARIABLES |
| 73 | 69 | //============================================================ |
| r2988 | r2989 | |
| 178 | 174 | } |
| 179 | 175 | |
| 180 | 176 | |
| 177 | //============================================================ |
| 178 | // get_modes - code take from SDL_Compat |
| 179 | //============================================================ |
| 181 | 180 | |
| 181 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 182 | static SDL_Rect **get_current_display_modes(void) |
| 183 | { |
| 184 | /* Get modes for current select display */ |
| 185 | int i, nmodes; |
| 186 | SDL_Rect **modes; |
| 187 | |
| 188 | /* Memory leak, but this is a compatibility function, who cares? */ |
| 189 | nmodes = 0; |
| 190 | modes = NULL; |
| 191 | for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
| 192 | SDL_DisplayMode mode; |
| 193 | SDL_GetDisplayMode(i, &mode); |
| 194 | if (!mode.w || !mode.h) { |
| 195 | return (SDL_Rect **) (NULL); |
| 196 | } |
| 197 | // FIXME: refresh rates |
| 198 | if (nmodes > 0 && modes[nmodes - 1]->w == mode.w |
| 199 | && modes[nmodes - 1]->h == mode.h) { |
| 200 | continue; |
| 201 | } |
| 202 | |
| 203 | modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes)); |
| 204 | if (!modes) { |
| 205 | return NULL; |
| 206 | } |
| 207 | modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect)); |
| 208 | if (!modes[nmodes]) { |
| 209 | return NULL; |
| 210 | } |
| 211 | modes[nmodes]->x = 0; |
| 212 | modes[nmodes]->y = 0; |
| 213 | modes[nmodes]->w = mode.w; |
| 214 | modes[nmodes]->h = mode.h; |
| 215 | mame_printf_verbose("Display mode #%d - %d x %d\n", nmodes, mode.w, mode.h); |
| 216 | ++nmodes; |
| 217 | } |
| 218 | if (modes) { |
| 219 | modes[nmodes] = NULL; |
| 220 | } |
| 221 | return modes; |
| 222 | } |
| 223 | #endif |
| 224 | |
| 225 | |
| 226 | |
| 182 | 227 | //============================================================ |
| 183 | 228 | // sdlvideo_monitor_refresh |
| 184 | 229 | //============================================================ |
| 185 | 230 | |
| 186 | 231 | void sdlvideo_monitor_refresh(sdl_monitor_info *monitor) |
| 187 | 232 | { |
| 188 | | #if defined(SDLMAME_WIN32) // Win32 version |
| 189 | | MONITORINFOEX info; |
| 190 | | info.cbSize = sizeof(info); |
| 191 | | GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info); |
| 192 | | monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left; |
| 193 | | monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; |
| 194 | | strcpy(monitor->monitor_device, info.szDevice); |
| 195 | | #elif (SDL_VERSION_ATLEAST(1,3,0)) |
| 233 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 196 | 234 | SDL_DisplayMode dmode; |
| 197 | 235 | |
| 198 | 236 | SDL_SelectVideoDisplay(monitor->handle); |
| r2988 | r2989 | |
| 201 | 239 | monitor->monitor_height = dmode.h; |
| 202 | 240 | monitor->center_width = dmode.w; |
| 203 | 241 | monitor->center_height = dmode.h; |
| 242 | #else |
| 243 | #if defined(SDLMAME_WIN32) // Win32 version |
| 244 | MONITORINFOEX info; |
| 245 | info.cbSize = sizeof(info); |
| 246 | GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info); |
| 247 | monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left; |
| 248 | monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; |
| 249 | strcpy(monitor->monitor_device, info.szDevice); |
| 204 | 250 | #elif defined(SDLMAME_MACOSX) // Mac OS X Core Imaging version |
| 205 | 251 | CGDirectDisplayID primary; |
| 206 | 252 | CGRect dbounds; |
| r2988 | r2989 | |
| 295 | 341 | #endif |
| 296 | 342 | |
| 297 | 343 | { |
| 298 | | //FIXME: Code not really suitable for multiple monitors |
| 299 | 344 | static int info_shown=0; |
| 300 | 345 | if (!info_shown) |
| 301 | 346 | { |
| r2988 | r2989 | |
| 304 | 349 | info_shown = 1; |
| 305 | 350 | } |
| 306 | 351 | } |
| 352 | #endif // (SDL_VERSION_ATLEAST(1,3,0)) |
| 307 | 353 | } |
| 308 | 354 | |
| 309 | 355 | |
| r2988 | r2989 | |
| 340 | 386 | return NULL; |
| 341 | 387 | } |
| 342 | 388 | |
| 389 | |
| 343 | 390 | //============================================================ |
| 344 | 391 | // osd_update |
| 345 | 392 | //============================================================ |
| r2988 | r2989 | |
| 365 | 412 | debugwin_update_during_game(); |
| 366 | 413 | } |
| 367 | 414 | |
| 415 | |
| 368 | 416 | //============================================================ |
| 369 | 417 | // add_primary_monitor |
| 370 | 418 | //============================================================ |
| 419 | |
| 371 | 420 | #if !defined(SDLMAME_WIN32) && !(SDL_VERSION_ATLEAST(1,3,0)) |
| 372 | 421 | static void add_primary_monitor(void *data) |
| 373 | 422 | { |
| r2988 | r2989 | |
| 395 | 444 | } |
| 396 | 445 | #endif |
| 397 | 446 | |
| 447 | |
| 398 | 448 | //============================================================ |
| 399 | 449 | // monitor_enum_callback |
| 400 | 450 | //============================================================ |
| 451 | |
| 401 | 452 | #ifdef SDLMAME_WIN32 |
| 402 | 453 | static BOOL CALLBACK monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect, LPARAM data) |
| 403 | 454 | { |
| r2988 | r2989 | |
| 437 | 488 | } |
| 438 | 489 | #endif |
| 439 | 490 | |
| 491 | |
| 440 | 492 | //============================================================ |
| 441 | 493 | // init_monitors |
| 442 | 494 | //============================================================ |
| r2988 | r2989 | |
| 451 | 503 | |
| 452 | 504 | #ifdef SDLMAME_WIN32 |
| 453 | 505 | EnumDisplayMonitors(NULL, NULL, monitor_enum_callback, (LPARAM)&tailptr); |
| 506 | monitor->modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_DOUBLEBUF); |
| 454 | 507 | #elif (SDL_VERSION_ATLEAST(1,3,0)) |
| 455 | 508 | { |
| 456 | | int i; |
| 509 | int i, temp; |
| 457 | 510 | |
| 511 | temp = SDL_GetCurrentVideoDisplay(); |
| 512 | |
| 458 | 513 | for (i = 0; i < SDL_GetNumVideoDisplays(); i++) |
| 459 | 514 | { |
| 460 | 515 | sdl_monitor_info *monitor; |
| r2988 | r2989 | |
| 466 | 521 | |
| 467 | 522 | snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", SDLOPTION_SCREEN(""),i); |
| 468 | 523 | |
| 524 | SDL_SelectVideoDisplay(i); |
| 469 | 525 | SDL_GetDesktopDisplayMode(&dmode); |
| 470 | 526 | monitor->monitor_width = dmode.w; |
| 471 | 527 | monitor->monitor_height = dmode.h; |
| r2988 | r2989 | |
| 475 | 531 | // guess the aspect ratio assuming square pixels |
| 476 | 532 | monitor->aspect = (float)(dmode.w) / (float)(dmode.h); |
| 477 | 533 | mame_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->monitor_device, dmode.w, dmode.h); |
| 534 | |
| 535 | monitor->modes = get_current_display_modes(); |
| 478 | 536 | |
| 479 | 537 | // save the primary monitor handle |
| 480 | 538 | if (i == 0) |
| r2988 | r2989 | |
| 484 | 542 | *tailptr = monitor; |
| 485 | 543 | tailptr = &monitor->next; |
| 486 | 544 | } |
| 545 | SDL_SelectVideoDisplay(temp); |
| 487 | 546 | } |
| 488 | 547 | #else |
| 489 | 548 | add_primary_monitor((void *)&tailptr); |
| 549 | sdl_monitor_list->modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_DOUBLEBUF); |
| 490 | 550 | #endif |
| 491 | 551 | } |
| 492 | 552 | |
| 553 | |
| 493 | 554 | //============================================================ |
| 494 | 555 | // pick_monitor |
| 495 | 556 | //============================================================ |
| r2988 | r2989 | |
| 558 | 619 | } |
| 559 | 620 | #endif |
| 560 | 621 | |
| 622 | |
| 561 | 623 | //============================================================ |
| 562 | 624 | // check_osd_inputs |
| 563 | 625 | //============================================================ |
| r2988 | r2989 | |
| 572 | 634 | |
| 573 | 635 | if (ui_input_pressed(machine, IPT_OSD_2)) |
| 574 | 636 | { |
| 637 | //FIXME: on a per window basis |
| 575 | 638 | video_config.fullstretch = !video_config.fullstretch; |
| 576 | 639 | ui_popup_time(1, "Uneven stretch %s", video_config.fullstretch? "enabled":"disabled"); |
| 577 | 640 | } |
| 578 | 641 | |
| 579 | 642 | if (ui_input_pressed(machine, IPT_OSD_4)) |
| 580 | 643 | { |
| 644 | //FIXME: on a per window basis |
| 581 | 645 | video_config.keepaspect = !video_config.keepaspect; |
| 582 | 646 | ui_popup_time(1, "Keepaspect %s", video_config.keepaspect? "enabled":"disabled"); |
| 583 | 647 | } |
| 584 | 648 | |
| 585 | 649 | if (USE_OPENGL) |
| 586 | 650 | { |
| 651 | //FIXME: on a per window basis |
| 587 | 652 | if (ui_input_pressed(machine, IPT_OSD_5)) |
| 588 | 653 | { |
| 589 | 654 | video_config.filter = !video_config.filter; |
| r2988 | r2989 | |
| 608 | 673 | } |
| 609 | 674 | |
| 610 | 675 | |
| 611 | | |
| 612 | 676 | //============================================================ |
| 613 | 677 | // extract_video_config |
| 614 | 678 | //============================================================ |
| r2988 | r2989 | |
| 674 | 738 | video_config.centerh = options_get_bool(mame_options(), SDLOPTION_CENTERH); |
| 675 | 739 | video_config.centerv = options_get_bool(mame_options(), SDLOPTION_CENTERV); |
| 676 | 740 | |
| 677 | | #if USE_OPENGL |
| 678 | | video_config.prescale = options_get_int(mame_options(), SDLOPTION_PRESCALE); |
| 679 | | if (video_config.prescale < 1 || video_config.prescale > 3) |
| 741 | if (USE_OPENGL) |
| 680 | 742 | { |
| 681 | | mame_printf_warning("Invalid prescale option, reverting to '1'\n"); |
| 682 | | video_config.prescale = 1; |
| 683 | | } |
| 684 | | // default to working video please |
| 685 | | video_config.prefer16bpp_tex = 0; |
| 686 | | video_config.filter = options_get_bool(mame_options(), SDLOPTION_FILTER); |
| 687 | | video_config.forcepow2texture = options_get_bool(mame_options(), SDLOPTION_GL_FORCEPOW2TEXTURE)==1; |
| 688 | | video_config.allowtexturerect = options_get_bool(mame_options(), SDLOPTION_GL_NOTEXTURERECT)==0; |
| 689 | | video_config.vbo = options_get_bool(mame_options(), SDLOPTION_GL_VBO); |
| 690 | | video_config.pbo = options_get_bool(mame_options(), SDLOPTION_GL_PBO); |
| 691 | | video_config.glsl = options_get_bool(mame_options(), SDLOPTION_GL_GLSL); |
| 692 | | if ( video_config.glsl ) |
| 693 | | { |
| 694 | | int i; |
| 695 | | static char buffer[20]; // gl_glsl_filter[0..9]? |
| 696 | | |
| 697 | | video_config.glsl_filter = options_get_int (mame_options(), SDLOPTION_GLSL_FILTER); |
| 698 | | |
| 699 | | video_config.glsl_shader_mamebm_num=0; |
| 700 | | |
| 701 | | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 743 | video_config.prescale = options_get_int(mame_options(), SDLOPTION_PRESCALE); |
| 744 | if (video_config.prescale < 1 || video_config.prescale > 3) |
| 702 | 745 | { |
| 703 | | snprintf(buffer, 18, SDLOPTION_SHADER_MAME("%d"), i); buffer[17]=0; |
| 704 | | |
| 705 | | stemp = options_get_string(mame_options(), buffer); |
| 706 | | if (stemp && strcmp(stemp, SDLOPTVAL_NONE) != 0 && strlen(stemp)>0) |
| 746 | mame_printf_warning("Invalid prescale option, reverting to '1'\n"); |
| 747 | video_config.prescale = 1; |
| 748 | } |
| 749 | // default to working video please |
| 750 | video_config.prefer16bpp_tex = 0; |
| 751 | video_config.filter = options_get_bool(mame_options(), SDLOPTION_FILTER); |
| 752 | video_config.forcepow2texture = options_get_bool(mame_options(), SDLOPTION_GL_FORCEPOW2TEXTURE)==1; |
| 753 | video_config.allowtexturerect = options_get_bool(mame_options(), SDLOPTION_GL_NOTEXTURERECT)==0; |
| 754 | video_config.vbo = options_get_bool(mame_options(), SDLOPTION_GL_VBO); |
| 755 | video_config.pbo = options_get_bool(mame_options(), SDLOPTION_GL_PBO); |
| 756 | video_config.glsl = options_get_bool(mame_options(), SDLOPTION_GL_GLSL); |
| 757 | if ( video_config.glsl ) |
| 758 | { |
| 759 | int i; |
| 760 | static char buffer[20]; // gl_glsl_filter[0..9]? |
| 761 | |
| 762 | video_config.glsl_filter = options_get_int (mame_options(), SDLOPTION_GLSL_FILTER); |
| 763 | |
| 764 | video_config.glsl_shader_mamebm_num=0; |
| 765 | |
| 766 | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 707 | 767 | { |
| 708 | | video_config.glsl_shader_mamebm[i] = (char *) malloc(strlen(stemp)+1); |
| 709 | | strcpy(video_config.glsl_shader_mamebm[i], stemp); |
| 710 | | video_config.glsl_shader_mamebm_num++; |
| 711 | | } else { |
| 768 | snprintf(buffer, 18, SDLOPTION_SHADER_MAME("%d"), i); buffer[17]=0; |
| 769 | |
| 770 | stemp = options_get_string(mame_options(), buffer); |
| 771 | if (stemp && strcmp(stemp, SDLOPTVAL_NONE) != 0 && strlen(stemp)>0) |
| 772 | { |
| 773 | video_config.glsl_shader_mamebm[i] = (char *) malloc(strlen(stemp)+1); |
| 774 | strcpy(video_config.glsl_shader_mamebm[i], stemp); |
| 775 | video_config.glsl_shader_mamebm_num++; |
| 776 | } else { |
| 777 | video_config.glsl_shader_mamebm[i] = NULL; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | video_config.glsl_shader_scrn_num=0; |
| 782 | |
| 783 | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 784 | { |
| 785 | snprintf(buffer, 20, SDLOPTION_SHADER_SCREEN("%d"), i); buffer[19]=0; |
| 786 | |
| 787 | stemp = options_get_string(mame_options(), buffer); |
| 788 | if (stemp && strcmp(stemp, SDLOPTVAL_NONE) != 0 && strlen(stemp)>0) |
| 789 | { |
| 790 | video_config.glsl_shader_scrn[i] = (char *) malloc(strlen(stemp)+1); |
| 791 | strcpy(video_config.glsl_shader_scrn[i], stemp); |
| 792 | video_config.glsl_shader_scrn_num++; |
| 793 | } else { |
| 794 | video_config.glsl_shader_scrn[i] = NULL; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | video_config.glsl_vid_attributes = options_get_int (mame_options(), SDLOPTION_GL_GLSL_VID_ATTR); |
| 799 | { |
| 800 | // Disable feature: glsl_vid_attributes, as long we have the gamma calculation |
| 801 | // disabled within the direct shaders .. -> too slow. |
| 802 | // IMHO the gamma setting should be done global anyways, and for the whole system, |
| 803 | // not just MAME .. |
| 804 | float gamma = options_get_float(mame_options(), OPTION_GAMMA); |
| 805 | if (gamma != 1.0 && video_config.glsl_vid_attributes && video_config.glsl) |
| 806 | { |
| 807 | video_config.glsl_vid_attributes = FALSE; |
| 808 | mame_printf_warning("OpenGL: GLSL - disable handling of brightness and contrast, gamma is set to %f\n", gamma); |
| 809 | } |
| 810 | } |
| 811 | } else { |
| 812 | int i; |
| 813 | video_config.glsl_filter = 0; |
| 814 | video_config.glsl_shader_mamebm_num=0; |
| 815 | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 816 | { |
| 712 | 817 | video_config.glsl_shader_mamebm[i] = NULL; |
| 713 | 818 | } |
| 714 | | } |
| 715 | | |
| 716 | | video_config.glsl_shader_scrn_num=0; |
| 717 | | |
| 718 | | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 719 | | { |
| 720 | | snprintf(buffer, 20, SDLOPTION_SHADER_SCREEN("%d"), i); buffer[19]=0; |
| 721 | | |
| 722 | | stemp = options_get_string(mame_options(), buffer); |
| 723 | | if (stemp && strcmp(stemp, SDLOPTVAL_NONE) != 0 && strlen(stemp)>0) |
| 819 | video_config.glsl_shader_scrn_num=0; |
| 820 | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 724 | 821 | { |
| 725 | | video_config.glsl_shader_scrn[i] = (char *) malloc(strlen(stemp)+1); |
| 726 | | strcpy(video_config.glsl_shader_scrn[i], stemp); |
| 727 | | video_config.glsl_shader_scrn_num++; |
| 728 | | } else { |
| 729 | 822 | video_config.glsl_shader_scrn[i] = NULL; |
| 730 | 823 | } |
| 824 | video_config.glsl_vid_attributes = 0; |
| 731 | 825 | } |
| 732 | | |
| 733 | | video_config.glsl_vid_attributes = options_get_int (mame_options(), SDLOPTION_GL_GLSL_VID_ATTR); |
| 734 | | { |
| 735 | | // Disable feature: glsl_vid_attributes, as long we have the gamma calculation |
| 736 | | // disabled within the direct shaders .. -> too slow. |
| 737 | | // IMHO the gamma setting should be done global anyways, and for the whole system, |
| 738 | | // not just MAME .. |
| 739 | | float gamma = options_get_float(mame_options(), OPTION_GAMMA); |
| 740 | | if (gamma != 1.0 && video_config.glsl_vid_attributes && video_config.glsl) |
| 741 | | { |
| 742 | | video_config.glsl_vid_attributes = FALSE; |
| 743 | | mame_printf_warning("OpenGL: GLSL - disable handling of brightness and contrast, gamma is set to %f\n", gamma); |
| 744 | | } |
| 745 | | } |
| 746 | | } else { |
| 747 | | int i; |
| 748 | | video_config.glsl_filter = 0; |
| 749 | | video_config.glsl_shader_mamebm_num=0; |
| 750 | | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 751 | | { |
| 752 | | video_config.glsl_shader_mamebm[i] = NULL; |
| 753 | | } |
| 754 | | video_config.glsl_shader_scrn_num=0; |
| 755 | | for(i=0; i<GLSL_SHADER_MAX; i++) |
| 756 | | { |
| 757 | | video_config.glsl_shader_scrn[i] = NULL; |
| 758 | | } |
| 759 | | video_config.glsl_vid_attributes = 0; |
| 826 | |
| 827 | if (sdl_use_unsupported()) |
| 828 | video_config.prescale_effect = options_get_int(mame_options(), SDLOPTION_PRESCALE_EFFECT); |
| 829 | else |
| 830 | video_config.prescale_effect = 0; |
| 760 | 831 | } |
| 761 | | |
| 762 | | if (sdl_use_unsupported()) |
| 763 | | video_config.prescale_effect = options_get_int(mame_options(), SDLOPTION_PRESCALE_EFFECT); |
| 764 | | else |
| 765 | | video_config.prescale_effect = 0; |
| 766 | | #endif |
| 767 | 832 | // misc options: sanity check values |
| 768 | 833 | |
| 769 | 834 | // global options: sanity check values |
| r2988 | r2989 | |
| 781 | 846 | } |
| 782 | 847 | #endif |
| 783 | 848 | // yuv settings ... |
| 784 | | stemp = options_get_string(mame_options(), SDLOPTION_YUVMODE); |
| 849 | stemp = options_get_string(mame_options(), SDLOPTION_SCALEMODE); |
| 785 | 850 | if (strcmp(stemp, SDLOPTVAL_NONE) == 0) |
| 786 | | video_config.yuv_mode = VIDEO_YUV_MODE_NONE; |
| 851 | video_config.scale_mode = VIDEO_SCALE_MODE_NONE; |
| 852 | else if (strcmp(stemp, SDLOPTVAL_HWBLIT) == 0) |
| 853 | video_config.scale_mode = VIDEO_SCALE_MODE_HWBLIT; |
| 787 | 854 | else if (strcmp(stemp, SDLOPTVAL_YV12) == 0) |
| 788 | | video_config.yuv_mode = VIDEO_YUV_MODE_YV12; |
| 855 | video_config.scale_mode = VIDEO_SCALE_MODE_YV12; |
| 789 | 856 | else if (strcmp(stemp, SDLOPTVAL_YV12x2) == 0) |
| 790 | | video_config.yuv_mode = VIDEO_YUV_MODE_YV12X2; |
| 857 | video_config.scale_mode = VIDEO_SCALE_MODE_YV12X2; |
| 791 | 858 | else if (strcmp(stemp, SDLOPTVAL_YUY2) == 0) |
| 792 | | video_config.yuv_mode = VIDEO_YUV_MODE_YUY2; |
| 859 | video_config.scale_mode = VIDEO_SCALE_MODE_YUY2; |
| 793 | 860 | else if (strcmp(stemp, SDLOPTVAL_YUY2x2) == 0) |
| 794 | | video_config.yuv_mode = VIDEO_YUV_MODE_YUY2X2; |
| 861 | video_config.scale_mode = VIDEO_SCALE_MODE_YUY2X2; |
| 795 | 862 | else |
| 796 | 863 | { |
| 797 | 864 | mame_printf_warning("Invalid yuvmode value %s; reverting to none\n", stemp); |
| 798 | | video_config.yuv_mode = VIDEO_YUV_MODE_NONE; |
| 865 | video_config.scale_mode = VIDEO_SCALE_MODE_NONE; |
| 799 | 866 | } |
| 800 | | if ( (video_config.mode != VIDEO_MODE_SOFT) && (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) ) |
| 867 | if ( (video_config.mode != VIDEO_MODE_SOFT) && (video_config.scale_mode != VIDEO_SCALE_MODE_NONE) ) |
| 801 | 868 | { |
| 802 | | mame_printf_warning("yuvmode is only for -video soft, overriding\n"); |
| 803 | | video_config.yuv_mode = VIDEO_YUV_MODE_NONE; |
| 869 | mame_printf_warning("scalemode is only for -video soft, overriding\n"); |
| 870 | video_config.scale_mode = VIDEO_SCALE_MODE_NONE; |
| 804 | 871 | } |
| 872 | if ( !SDL_VERSION_ATLEAST(1,3,0) && (video_config.mode == VIDEO_MODE_SOFT) && (video_config.scale_mode == VIDEO_SCALE_MODE_HWBLIT) ) |
| 873 | { |
| 874 | mame_printf_warning("scalemode 'hwblit' treated like 'none' in SDL1.2\n"); |
| 875 | } |
| 805 | 876 | } |
| 806 | 877 | |
| 807 | 878 | |
| r2988 | r2989 | |
| 861 | 932 | } |
| 862 | 933 | |
| 863 | 934 | |
| 864 | | |
| 865 | 935 | //============================================================ |
| 866 | 936 | // get_resolution |
| 867 | 937 | //============================================================ |
src/osd/sdl/window.c
| r2988 | r2989 | |
| 52 | 52 | #define WINDOW_DECORATION_WIDTH (8) // should be more than plenty |
| 53 | 53 | #define WINDOW_DECORATION_HEIGHT (48) // title bar + bottom drag region |
| 54 | 54 | |
| 55 | | #if 1 |
| 55 | #ifdef MAME_DEBUG |
| 56 | 56 | #define ASSERT_USE(x) assert_always(SDL_ThreadID() == x, "Wrong Thread") |
| 57 | | //#define ASSERT_USE(x) |
| 58 | 57 | #else |
| 59 | | #define ASSERT_USE(x) assert(SDL_ThreadID() == x) |
| 58 | #define ASSERT_USE(x) do {} while (0) |
| 59 | //#define ASSERT_USE(x) assert(SDL_ThreadID() == x) |
| 60 | 60 | #endif |
| 61 | 61 | |
| 62 | 62 | #define ASSERT_REDRAW_THREAD() ASSERT_USE(window_threadid) |
| r2988 | r2989 | |
| 79 | 79 | #define WMSZ_RIGHT (7) |
| 80 | 80 | #endif |
| 81 | 81 | |
| 82 | |
| 82 | 83 | //============================================================ |
| 83 | 84 | // GLOBAL VARIABLES |
| 84 | 85 | //============================================================ |
| r2988 | r2989 | |
| 98 | 99 | static int main_threadid; |
| 99 | 100 | static int window_threadid; |
| 100 | 101 | |
| 101 | | static const char *yuv_mode_names[] = { "none", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 102 | static const char *scale_mode_names[] = { "none", "hwblit", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 102 | 103 | |
| 104 | |
| 103 | 105 | // debugger |
| 104 | 106 | //static int in_background; |
| 105 | 107 | |
| 106 | | static sdl_draw_callbacks draw; |
| 108 | static sdl_draw_info draw; |
| 107 | 109 | |
| 108 | 110 | typedef struct _worker_param worker_param; |
| 109 | 111 | struct _worker_param { |
| r2988 | r2989 | |
| 148 | 150 | wp->resize_new_height=0; |
| 149 | 151 | } |
| 150 | 152 | |
| 153 | |
| 151 | 154 | //============================================================ |
| 152 | 155 | // execute_async |
| 153 | 156 | //============================================================ |
| 154 | 157 | |
| 158 | |
| 155 | 159 | INLINE void execute_async(osd_work_callback callback, worker_param *wp) |
| 156 | 160 | { |
| 157 | 161 | worker_param *wp_temp = NULL; |
| r2988 | r2989 | |
| 168 | 172 | callback((void *) wp_temp, 0); |
| 169 | 173 | } |
| 170 | 174 | |
| 175 | |
| 171 | 176 | //============================================================ |
| 172 | 177 | // execute_async_wait |
| 173 | 178 | //============================================================ |
| r2988 | r2989 | |
| 178 | 183 | sdlwindow_sync(); |
| 179 | 184 | } |
| 180 | 185 | |
| 186 | |
| 181 | 187 | //============================================================ |
| 182 | 188 | // sdlwindow_thread_id |
| 183 | 189 | // (window thread) |
| r2988 | r2989 | |
| 198 | 204 | return NULL; |
| 199 | 205 | } |
| 200 | 206 | |
| 207 | |
| 201 | 208 | //============================================================ |
| 202 | 209 | // win_init_window |
| 203 | 210 | // (main thread) |
| r2988 | r2989 | |
| 267 | 274 | } |
| 268 | 275 | } |
| 269 | 276 | |
| 277 | |
| 270 | 278 | //============================================================ |
| 271 | 279 | // sdlwindow_exit |
| 272 | 280 | // (main thread) |
| r2988 | r2989 | |
| 281 | 289 | return NULL; |
| 282 | 290 | } |
| 283 | 291 | |
| 292 | |
| 284 | 293 | static void sdlwindow_exit(running_machine *machine) |
| 285 | 294 | { |
| 286 | 295 | ASSERT_MAIN_THREAD(); |
| r2988 | r2989 | |
| 312 | 321 | |
| 313 | 322 | } |
| 314 | 323 | |
| 324 | |
| 315 | 325 | //============================================================ |
| 316 | 326 | // sdlwindow_blit_surface_size |
| 317 | 327 | //============================================================ |
| r2988 | r2989 | |
| 343 | 353 | desired_aspect = (float)target_width / (float)target_height; |
| 344 | 354 | } |
| 345 | 355 | |
| 346 | | // non-integer scaling - often gives more pleasing results in full screen |
| 347 | | if (!video_config.fullstretch) |
| 356 | // non-integer scaling - often gives more pleasing results in full screen |
| 357 | if (!video_config.fullstretch) |
| 348 | 358 | { |
| 349 | 359 | // compute maximum integral scaling to fit the window |
| 350 | 360 | xscale = (target_width + 2) / newwidth; |
| r2988 | r2989 | |
| 391 | 401 | } |
| 392 | 402 | |
| 393 | 403 | if ((render_target_get_layer_config(window->target) & LAYER_CONFIG_ZOOM_TO_SCREEN) |
| 394 | | && video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 404 | && (window->scale_mode == VIDEO_SCALE_MODE_NONE || (!SDL_VERSION_ATLEAST(1,3,0) && !IS_YUV_MODE(window->scale_mode)))) |
| 395 | 405 | newwidth = window_width; |
| 396 | 406 | |
| 397 | 407 | if ((window->blitwidth != newwidth) || (window->blitheight != newheight)) |
| r2988 | r2989 | |
| 414 | 424 | |
| 415 | 425 | ASSERT_WINDOW_THREAD(); |
| 416 | 426 | |
| 417 | | draw.window_destroy_all_textures(window); |
| 418 | | draw.window_resize(window, wp->resize_new_width, wp->resize_new_height); |
| 427 | window->destroy_all_textures(window); |
| 428 | window->resize(window, wp->resize_new_width, wp->resize_new_height); |
| 419 | 429 | |
| 420 | 430 | sdlwindow_blit_surface_size(window, wp->resize_new_width, wp->resize_new_height); |
| 421 | 431 | |
| r2988 | r2989 | |
| 442 | 452 | execute_async_wait(&sdlwindow_resize_wt, &wp); |
| 443 | 453 | } |
| 444 | 454 | |
| 455 | |
| 445 | 456 | //============================================================ |
| 446 | 457 | // sdlwindow_clear_surface |
| 447 | 458 | // (window thread) |
| r2988 | r2989 | |
| 454 | 465 | |
| 455 | 466 | ASSERT_WINDOW_THREAD(); |
| 456 | 467 | |
| 457 | | draw.window_clear(window); |
| 468 | window->clear(window); |
| 458 | 469 | free(wp); |
| 459 | 470 | return NULL; |
| 460 | 471 | } |
| r2988 | r2989 | |
| 475 | 486 | sdlwindow_clear_surface_wt( (void *) wp, 0); |
| 476 | 487 | } |
| 477 | 488 | |
| 489 | |
| 478 | 490 | //============================================================ |
| 479 | 491 | // sdlwindow_toggle_full_screen |
| 480 | 492 | // (main thread) |
| r2988 | r2989 | |
| 498 | 510 | window->windowed_height = window->height; |
| 499 | 511 | } |
| 500 | 512 | |
| 501 | | (*draw.window_destroy)(window); |
| 513 | window->destroy(window); |
| 502 | 514 | |
| 503 | 515 | // toggle the window mode |
| 504 | 516 | window->fullscreen = !window->fullscreen; |
| r2988 | r2989 | |
| 517 | 529 | clear_worker_param(&wp); |
| 518 | 530 | wp.window = window; |
| 519 | 531 | |
| 532 | //FIMXE: Reset Key state .... |
| 520 | 533 | execute_async_wait(&sdlwindow_toggle_full_screen_wt, &wp); |
| 521 | 534 | } |
| 522 | 535 | |
| 523 | | static void sdlwindow_modify_yuv(running_machine *machine, int dir) |
| 536 | static void sdlwindow_modify_yuv(running_machine *machine, sdl_window_info *window, int dir) |
| 524 | 537 | { |
| 525 | | int new_yuv_mode = video_config.yuv_mode; |
| 526 | | sdl_window_info *window = sdlinput_get_focus_window(machine); |
| 538 | int new_scale_mode = window->scale_mode; |
| 527 | 539 | |
| 528 | | if (dir > 0 && video_config.yuv_mode < VIDEO_YUV_MODE_MAX) |
| 529 | | new_yuv_mode = video_config.yuv_mode + 1; |
| 530 | | if (dir < 0 && video_config.yuv_mode > VIDEO_YUV_MODE_MIN) |
| 531 | | new_yuv_mode = video_config.yuv_mode - 1; |
| 540 | if (dir > 0 && window->scale_mode < VIDEO_SCALE_MODE_MAX) |
| 541 | new_scale_mode = window->scale_mode + 1; |
| 542 | if (dir < 0 && window->scale_mode > VIDEO_SCALE_MODE_MIN) |
| 543 | new_scale_mode = window->scale_mode - 1; |
| 532 | 544 | |
| 533 | | if (new_yuv_mode != video_config.yuv_mode) |
| 545 | // FIXME: Changing to yv12 mode from video_mode none does not work |
| 546 | if (new_scale_mode != window->scale_mode) |
| 534 | 547 | { |
| 535 | 548 | worker_param wp; |
| 536 | 549 | |
| 537 | 550 | clear_worker_param(&wp); |
| 538 | 551 | wp.window = window; |
| 552 | sdlwindow_sync(); |
| 539 | 553 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 540 | 554 | |
| 541 | | video_config.yuv_mode = new_yuv_mode; |
| 555 | window->scale_mode = new_scale_mode; |
| 542 | 556 | execute_async_wait(&complete_create_wt, &wp); |
| 557 | sdlwindow_sync(); |
| 543 | 558 | |
| 544 | | ui_popup_time(1, "YUV mode %s", yuv_mode_names[video_config.yuv_mode]); |
| 559 | ui_popup_time(1, "YUV mode %s", scale_mode_names[window->scale_mode]); |
| 560 | mame_printf_verbose("YUV mode %s\n", scale_mode_names[window->scale_mode]); |
| 545 | 561 | } |
| 546 | 562 | } |
| 547 | 563 | |
| r2988 | r2989 | |
| 551 | 567 | |
| 552 | 568 | sdl_window_info *window = wp->window; |
| 553 | 569 | |
| 554 | | draw.window_destroy_all_textures(window); |
| 570 | window->destroy_all_textures(window); |
| 555 | 571 | |
| 556 | 572 | free(wp); |
| 557 | 573 | return NULL; |
| r2988 | r2989 | |
| 560 | 576 | void sdlwindow_modify_prescale(running_machine *machine, sdl_window_info *window, int dir) |
| 561 | 577 | { |
| 562 | 578 | worker_param wp; |
| 563 | | int new_prescale = video_config.prescale; |
| 579 | int new_prescale = window->prescale; |
| 564 | 580 | |
| 565 | 581 | clear_worker_param(&wp); |
| 566 | 582 | |
| 567 | 583 | wp.window = window; |
| 568 | 584 | |
| 569 | | if (dir > 0 && video_config.prescale < 3) |
| 570 | | new_prescale = video_config.prescale + 1; |
| 571 | | if (dir < 0 && video_config.prescale > 1) |
| 572 | | new_prescale = video_config.prescale - 1; |
| 585 | if (dir > 0 && window->prescale < 3) |
| 586 | new_prescale = window->prescale + 1; |
| 587 | if (dir < 0 && window->prescale > 1) |
| 588 | new_prescale = window->prescale - 1; |
| 573 | 589 | |
| 574 | | if (new_prescale != video_config.prescale) |
| 590 | if (new_prescale != window->prescale) |
| 575 | 591 | { |
| 576 | 592 | if (window->fullscreen && video_config.switchres) |
| 577 | 593 | { |
| 578 | 594 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 579 | 595 | |
| 580 | | video_config.prescale = new_prescale; |
| 596 | window->prescale = new_prescale; |
| 581 | 597 | |
| 582 | 598 | execute_async_wait(&complete_create_wt, &wp); |
| 583 | 599 | |
| r2988 | r2989 | |
| 585 | 601 | else |
| 586 | 602 | { |
| 587 | 603 | execute_async_wait(destroy_all_textures_wt, &wp); |
| 588 | | video_config.prescale = new_prescale; |
| 604 | window->prescale = new_prescale; |
| 589 | 605 | } |
| 590 | | ui_popup_time(1, "Prescale %d", video_config.prescale); |
| 606 | ui_popup_time(1, "Prescale %d", window->prescale); |
| 591 | 607 | } |
| 592 | 608 | } |
| 593 | 609 | |
| r2988 | r2989 | |
| 596 | 612 | |
| 597 | 613 | if (video_config.mode == VIDEO_MODE_SOFT) |
| 598 | 614 | { |
| 599 | | sdlwindow_modify_yuv(machine, dir); |
| 615 | sdlwindow_modify_yuv(machine, window, dir); |
| 600 | 616 | return; |
| 601 | 617 | } |
| 602 | | #if USE_OPENGL |
| 603 | | else |
| 618 | else if (USE_OPENGL) |
| 604 | 619 | { |
| 605 | | int new_prescale_effect = video_config.prescale_effect; |
| 620 | int new_prescale_effect = window->prescale_effect; |
| 606 | 621 | const char *effect_names[] = { "none", "scale2x" }; |
| 607 | 622 | |
| 608 | | if (dir > 0 && video_config.prescale_effect < 1) |
| 609 | | new_prescale_effect = video_config.prescale_effect + 1; |
| 610 | | if (dir < 0 && video_config.prescale_effect > 0) |
| 611 | | new_prescale_effect = video_config.prescale_effect - 1; |
| 623 | if (dir > 0 && window->prescale_effect < 1) |
| 624 | new_prescale_effect = window->prescale_effect + 1; |
| 625 | if (dir < 0 && window->prescale_effect > 0) |
| 626 | new_prescale_effect = window->prescale_effect - 1; |
| 612 | 627 | |
| 613 | | if (new_prescale_effect != video_config.prescale_effect) |
| 628 | if (new_prescale_effect != window->prescale_effect) |
| 614 | 629 | { |
| 615 | 630 | worker_param wp; |
| 616 | 631 | |
| r2988 | r2989 | |
| 618 | 633 | wp.window = window; |
| 619 | 634 | execute_async_wait(destroy_all_textures_wt, &wp); |
| 620 | 635 | |
| 621 | | video_config.prescale_effect = new_prescale_effect; |
| 622 | | ui_popup_time(1, "Effect: %s", effect_names[video_config.prescale_effect]); |
| 636 | window->prescale_effect = new_prescale_effect; |
| 637 | ui_popup_time(1, "Effect: %s", effect_names[window->prescale_effect]); |
| 623 | 638 | } |
| 624 | 639 | } |
| 625 | | #endif |
| 626 | 640 | } |
| 627 | 641 | |
| 628 | 642 | void sdlwindow_toggle_draw(running_machine *machine, sdl_window_info *window) |
| r2988 | r2989 | |
| 642 | 656 | wp.window = window; |
| 643 | 657 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 644 | 658 | |
| 645 | | video_config.yuv_mode = VIDEO_YUV_MODE_NONE; |
| 659 | window->scale_mode = VIDEO_SCALE_MODE_NONE; |
| 646 | 660 | |
| 647 | 661 | if (video_config.mode == VIDEO_MODE_OPENGL) |
| 648 | 662 | { |
| r2988 | r2989 | |
| 661 | 675 | #endif |
| 662 | 676 | } |
| 663 | 677 | |
| 678 | |
| 664 | 679 | //============================================================ |
| 665 | 680 | // sdlwindow_update_cursor_state |
| 666 | 681 | // (main or window thread) |
| r2988 | r2989 | |
| 669 | 684 | static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window) |
| 670 | 685 | { |
| 671 | 686 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 687 | // FIXME: belongs into callback |
| 672 | 688 | // do not do mouse capture if the debugger's enabled to avoid |
| 673 | 689 | // the possibility of losing control |
| 674 | 690 | if (!options_get_bool(mame_options(), OPTION_DEBUG)) |
| r2988 | r2989 | |
| 735 | 751 | window->depth = config->depth; |
| 736 | 752 | window->refresh = config->refresh; |
| 737 | 753 | window->monitor = monitor; |
| 754 | |
| 755 | //FIXME: these should be per_window in config-> |
| 738 | 756 | window->fullscreen = !video_config.windowed; |
| 757 | window->prescale = video_config.prescale; |
| 758 | window->prescale_effect = video_config.prescale_effect; |
| 759 | window->scale_mode = video_config.scale_mode; |
| 739 | 760 | |
| 740 | 761 | // set the initial maximized state |
| 762 | // FIXME: Does not belong here |
| 741 | 763 | window->startmaximized = options_get_bool(mame_options(), SDLOPTION_MAXIMIZE); |
| 742 | 764 | |
| 743 | 765 | if (!window->fullscreen) |
| r2988 | r2989 | |
| 751 | 773 | *last_window_ptr = window; |
| 752 | 774 | last_window_ptr = &window->next; |
| 753 | 775 | |
| 776 | draw.attach(&draw, window); |
| 777 | |
| 754 | 778 | // create a lock that we can use to skip blitting |
| 755 | 779 | window->render_lock = osd_lock_alloc(); |
| 756 | 780 | |
| r2988 | r2989 | |
| 806 | 830 | ASSERT_WINDOW_THREAD(); |
| 807 | 831 | |
| 808 | 832 | // free the textures etc |
| 809 | | (*draw.window_destroy)(window); |
| 833 | window->destroy(window); |
| 810 | 834 | |
| 811 | 835 | free(wp); |
| 812 | 836 | return NULL; |
| r2988 | r2989 | |
| 849 | 873 | free(window); |
| 850 | 874 | } |
| 851 | 875 | |
| 876 | |
| 852 | 877 | //============================================================ |
| 853 | 878 | // pick_best_mode |
| 854 | 879 | //============================================================ |
| r2988 | r2989 | |
| 856 | 881 | static void pick_best_mode(sdl_window_info *window, int *fswidth, int *fsheight) |
| 857 | 882 | { |
| 858 | 883 | int minimum_width, minimum_height, target_width, target_height; |
| 859 | | SDL_Rect **modes; |
| 860 | 884 | int i; |
| 861 | 885 | float size_score, best_score = 0.0f; |
| 886 | SDL_Rect **modes; |
| 862 | 887 | |
| 863 | 888 | // determine the minimum width/height for the selected target |
| 864 | 889 | render_target_get_minimum_size(window->target, &minimum_width, &minimum_height); |
| 865 | 890 | |
| 866 | 891 | // use those as the target for now |
| 867 | | target_width = minimum_width * MAX(1, video_config.prescale); |
| 868 | | target_height = minimum_height * MAX(1, video_config.prescale); |
| 892 | target_width = minimum_width * MAX(1, window->prescale); |
| 893 | target_height = minimum_height * MAX(1, window->prescale); |
| 869 | 894 | |
| 870 | 895 | // if we're not stretching, allow some slop on the minimum since we can handle it |
| 871 | 896 | { |
| r2988 | r2989 | |
| 873 | 898 | minimum_height -= 4; |
| 874 | 899 | } |
| 875 | 900 | |
| 876 | | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 877 | | // FIXME: Mode switching not supported! |
| 878 | | modes = NULL; |
| 879 | | #else |
| 880 | | modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_DOUBLEBUF); |
| 881 | | #endif |
| 901 | modes = window->monitor->modes; |
| 882 | 902 | |
| 883 | 903 | if (modes == (SDL_Rect **)0) |
| 884 | 904 | { |
| r2988 | r2989 | |
| 961 | 981 | } |
| 962 | 982 | } |
| 963 | 983 | |
| 964 | | // this: 'osd_lock_acquire', just to 'see' if rendering was still happening |
| 965 | | // is invalid. |
| 966 | | // 'osd_lock_acquire' puts us to the waiting queue and we will miss to be in sync with real-time |
| 967 | | // but throttle actually means to be in real time, i.e. to not render a few frames, |
| 968 | | // while rendering is still in progress is all fine .. |
| 969 | | #if 0 |
| 970 | | // only block if we're throttled |
| 971 | | if (video_config.throttle) |
| 972 | | osd_lock_acquire(window->render_lock); |
| 973 | | else |
| 974 | | #endif |
| 975 | | got_lock = osd_lock_try(window->render_lock); |
| 984 | got_lock = osd_lock_try(window->render_lock); |
| 976 | 985 | |
| 977 | 986 | // only render if we were able to get the lock |
| 978 | 987 | if (got_lock) |
| r2988 | r2989 | |
| 986 | 995 | osd_lock_release(window->render_lock); |
| 987 | 996 | |
| 988 | 997 | // ensure the target bounds are up-to-date, and then get the primitives |
| 989 | | primlist = draw.window_get_primitives(window); |
| 998 | primlist = window->get_primitives(window); |
| 990 | 999 | |
| 991 | 1000 | // and redraw now |
| 992 | 1001 | |
| r2988 | r2989 | |
| 1024 | 1033 | window->start_viewscreen=viewindex; |
| 1025 | 1034 | } |
| 1026 | 1035 | |
| 1036 | |
| 1027 | 1037 | //============================================================ |
| 1028 | 1038 | // complete_create |
| 1029 | 1039 | // (window thread) |
| r2988 | r2989 | |
| 1077 | 1087 | } |
| 1078 | 1088 | |
| 1079 | 1089 | // initialize the drawing backend |
| 1080 | | if ((*draw.window_create)(window, tempwidth, tempheight)) |
| 1090 | if (window->create(window, tempwidth, tempheight)) |
| 1081 | 1091 | return (void *) &result[1]; |
| 1082 | 1092 | |
| 1083 | 1093 | return (void *) &result[0]; |
| 1084 | 1094 | } |
| 1085 | 1095 | |
| 1096 | |
| 1086 | 1097 | //============================================================ |
| 1087 | 1098 | // draw_video_contents |
| 1088 | 1099 | // (window thread) |
| r2988 | r2989 | |
| 1114 | 1125 | |
| 1115 | 1126 | t0 = getusecs(); |
| 1116 | 1127 | |
| 1117 | | (*draw.window_draw)(window, dc, update); |
| 1128 | window->draw(window, dc, update); |
| 1118 | 1129 | |
| 1119 | 1130 | frames++; |
| 1120 | 1131 | currentTime = getusecs(); |
| r2988 | r2989 | |
| 1143 | 1154 | #else |
| 1144 | 1155 | static void measure_fps(sdl_window_info *window, UINT32 dc, int update) |
| 1145 | 1156 | { |
| 1146 | | (*draw.window_draw)(window, dc, update); |
| 1157 | window->draw(window, dc, update); |
| 1147 | 1158 | } |
| 1148 | 1159 | #endif |
| 1149 | 1160 | |
| r2988 | r2989 | |
| 1172 | 1183 | if( video_config.perftest ) |
| 1173 | 1184 | measure_fps(window, dc, update); |
| 1174 | 1185 | else |
| 1175 | | (*draw.window_draw)(window, dc, update); |
| 1186 | window->draw(window, dc, update); |
| 1176 | 1187 | } |
| 1177 | 1188 | osd_lock_release(window->render_lock); |
| 1178 | 1189 | free(wp); |
| r2988 | r2989 | |
| 1180 | 1191 | return NULL; |
| 1181 | 1192 | } |
| 1182 | 1193 | |
| 1194 | |
| 1183 | 1195 | //============================================================ |
| 1184 | 1196 | // constrain_to_aspect_ratio |
| 1185 | 1197 | // (window thread) |
| r2988 | r2989 | |
| 1264 | 1276 | *window_height = visheight; |
| 1265 | 1277 | } |
| 1266 | 1278 | |
| 1279 | |
| 1267 | 1280 | //============================================================ |
| 1268 | 1281 | // get_min_bounds |
| 1269 | 1282 | // (window thread) |
| r2988 | r2989 | |
| 1313 | 1326 | *window_height = minheight; |
| 1314 | 1327 | } |
| 1315 | 1328 | |
| 1329 | |
| 1316 | 1330 | //============================================================ |
| 1317 | 1331 | // get_max_bounds |
| 1318 | 1332 | // (window thread) |
src/osd/sdl/sdlmain.c
| r2988 | r2989 | |
| 110 | 110 | #if (SDL_VERSION_ATLEAST(1,2,10)) |
| 111 | 111 | { SDLOPTION_WAITVSYNC, "0", OPTION_BOOLEAN, "enable waiting for the start of VBLANK before flipping screens; reduces tearing effects" }, |
| 112 | 112 | #endif |
| 113 | | { SDLOPTION_YUVMODE ";ym", SDLOPTVAL_NONE, 0, "YUV mode: none, yv12, yuy2, yv12x2, yuy2x2 (-video soft only)" }, |
| 114 | | |
| 113 | { SDLOPTION_SCALEMODE ";sm", SDLOPTVAL_NONE, 0, "Scale mode: none, hwblit, yv12, yuy2, yv12x2, yuy2x2 (-video soft only)" }, |
| 115 | 114 | #if USE_OPENGL |
| 116 | 115 | // OpenGL specific options |
| 117 | 116 | { NULL, NULL, OPTION_HEADER, "OpenGL-SPECIFIC OPTIONS" }, |
| r2988 | r2989 | |
| 201 | 200 | { SDLOPTION_JOYMAP, "0", OPTION_BOOLEAN, "enable physical to logical joystick mapping" }, |
| 202 | 201 | { SDLOPTION_JOYMAP_FILE, "joymap.dat", 0, "joymap filename" }, |
| 203 | 202 | { SDLOPTION_SIXAXIS, "0", OPTION_BOOLEAN, "Use special handling for PS3 Sixaxis controllers" }, |
| 203 | |
| 204 | // SDL low level driver options |
| 205 | { NULL, NULL, OPTION_HEADER, "SDL LOWLEVEL DRIVER OPTIONS" }, |
| 206 | { SDLOPTION_VIDEODRIVER ";vd", SDLOPTVAL_AUTO, 0, "sdl video driver to use ('x11', 'directfb', ... or 'auto' for SDL default" }, |
| 207 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 208 | { SDLOPTION_RENDERDRIVER ";rd", SDLOPTVAL_AUTO, 0, "sdl render driver to use ('software', 'opengl', 'directfb' ... or 'auto' for SDL default" }, |
| 209 | #endif |
| 210 | { SDLOPTION_AUDIODRIVER ";ad", SDLOPTVAL_AUTO, 0, "sdl audio driver to use ('alsa', 'arts', ... or 'auto' for SDL default" }, |
| 211 | #if USE_OPENGL |
| 212 | { SDLOPTION_GL_LIB, SDLOPTVAL_GLLIB, 0, "alternative libGL.so to use; 'auto' for system default" }, |
| 213 | #endif |
| 214 | |
| 215 | // End of list |
| 204 | 216 | { NULL } |
| 205 | 217 | }; |
| 206 | 218 | |
| r2988 | r2989 | |
| 308 | 320 | char buf[130]; |
| 309 | 321 | if (XMatchVisualInfo(display, DefaultScreen(display), 24, TrueColor, &vi)) { |
| 310 | 322 | snprintf(buf, sizeof(buf), "0x%lx", vi.visualid); |
| 311 | | setenv(SDLENV_IDENTIFIER, buf, 0); |
| 323 | setenv(SDLENV_VISUALID, buf, 0); |
| 312 | 324 | } |
| 313 | 325 | } |
| 314 | 326 | if (display) |
| r2988 | r2989 | |
| 418 | 430 | //============================================================ |
| 419 | 431 | void osd_init(running_machine *machine) |
| 420 | 432 | { |
| 433 | const char *stemp; |
| 434 | |
| 435 | // Some driver options - must be before audio init! |
| 436 | stemp = options_get_string(mame_options(), SDLOPTION_AUDIODRIVER); |
| 437 | if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) |
| 438 | { |
| 439 | mame_printf_verbose("Setting SDL audiodriver '%s' ...\n", stemp); |
| 440 | setenv(SDLENV_AUDIODRIVER, stemp, 1); |
| 441 | } |
| 442 | |
| 443 | stemp = options_get_string(mame_options(), SDLOPTION_VIDEODRIVER); |
| 444 | if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) |
| 445 | { |
| 446 | mame_printf_verbose("Setting SDL videodriver '%s' ...\n", stemp); |
| 447 | setenv(SDLENV_VIDEODRIVER, stemp, 1); |
| 448 | } |
| 449 | |
| 450 | if (SDL_VERSION_ATLEAST(1,3,0)) |
| 451 | { |
| 452 | stemp = options_get_string(mame_options(), SDLOPTION_RENDERDRIVER); |
| 453 | if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) |
| 454 | { |
| 455 | mame_printf_verbose("Setting SDL renderdriver '%s' ...\n", stemp); |
| 456 | setenv(SDLENV_RENDERDRIVER, stemp, 1); |
| 457 | } |
| 458 | } |
| 459 | |
| 421 | 460 | if (!SDLMAME_INIT_IN_WORKER_THREAD) |
| 422 | 461 | { |
| 423 | 462 | if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) { |
| 424 | 463 | /* mame_printf_* not fully initialized yet */ |
| 425 | | ShowError("Could not initialize SDL: %s.\n", SDL_GetError()); |
| 464 | ShowError("Could not initialize SDL", SDL_GetError()); |
| 426 | 465 | exit(-1); |
| 427 | 466 | } |
| 428 | 467 | } |
| r2988 | r2989 | |
| 431 | 470 | |
| 432 | 471 | defines_verbose(); |
| 433 | 472 | |
| 434 | | #if defined(SDLMAME_NO_X11) || defined(SDLMAME_WIN32) |
| 435 | | if (options_get_bool(mame_options(), OPTION_DEBUG)) |
| 436 | | { |
| 437 | | osd_exit(machine); |
| 438 | | ShowError("sdlmame", "-debug not supported on X11-less builds\n\n"); |
| 439 | | exit(-1); |
| 440 | | } |
| 441 | | #endif |
| 473 | if (!SDLMAME_HAS_DEBUGGER) |
| 474 | if (options_get_bool(mame_options(), OPTION_DEBUG)) |
| 475 | { |
| 476 | osd_exit(machine); |
| 477 | ShowError("sdlmame", "-debug not supported on X11-less builds\n\n"); |
| 478 | exit(-1); |
| 479 | } |
| 442 | 480 | |
| 443 | 481 | if (sdlvideo_init(machine)) |
| 444 | 482 | { |
| r2988 | r2989 | |
| 456 | 494 | #endif |
| 457 | 495 | |
| 458 | 496 | sdlinput_init(machine); |
| 497 | |
| 459 | 498 | sdlaudio_init(machine); |
| 460 | 499 | |
| 461 | 500 | if (options_get_bool(mame_options(), SDLOPTION_OSLOG)) |
| 462 | 501 | add_logerror_callback(machine, output_oslog); |
| 463 | 502 | |
| 464 | | #ifdef MESS |
| 465 | | SDL_EnableUNICODE(1); |
| 466 | | #endif |
| 503 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 504 | SDL_EventState(SDL_TEXTINPUT, SDL_TRUE); |
| 505 | #else |
| 506 | SDL_EnableUNICODE(SDL_TRUE); |
| 507 | #endif |
| 467 | 508 | } |
| 468 | 509 | |
| 469 | 510 | #ifdef MESS |