src/osd/sdl/drawogl.c
| r2959 | r2960 | |
| 152 | 152 | #define GL_NO_PRIMITIVE -1 |
| 153 | 153 | |
| 154 | 154 | //============================================================ |
| 155 | // TYPES |
| 156 | //============================================================ |
| 157 | |
| 158 | /* sdl_info is the information about SDL for the current screen */ |
| 159 | typedef struct _sdl_info sdl_info; |
| 160 | struct _sdl_info |
| 161 | { |
| 162 | INT32 blittimer; |
| 163 | |
| 164 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 165 | SDL_GLContext gl_context_id; |
| 166 | #else |
| 167 | // SDL surface |
| 168 | SDL_Surface *sdlsurf; |
| 169 | #endif |
| 170 | |
| 171 | int initialized; // is everything well initialized, i.e. all GL stuff etc. |
| 172 | // 3D info (GL mode only) |
| 173 | texture_info * texlist; // list of active textures |
| 174 | int last_blendmode; // previous blendmode |
| 175 | INT32 texture_max_width; // texture maximum width |
| 176 | INT32 texture_max_height; // texture maximum height |
| 177 | int texpoweroftwo; // must textures be power-of-2 sized? |
| 178 | int usevbo; // runtime check if VBO is available |
| 179 | int usepbo; // runtime check if PBO is available |
| 180 | int usefbo; // runtime check if FBO is available |
| 181 | int useglsl; // runtime check if GLSL is available |
| 182 | |
| 183 | glsl_shader_info *glsl; // glsl_shader_info |
| 184 | |
| 185 | GLhandleARB glsl_program[2*GLSL_SHADER_MAX]; // GLSL programs, or 0 |
| 186 | int glsl_program_num; // number of GLSL programs |
| 187 | int glsl_program_mb2sc; // GLSL program idx, which transforms |
| 188 | // the mame-bitmap -> screen-bitmap (size/rotation/..) |
| 189 | // All progs <= glsl_program_mb2sc using the mame bitmap |
| 190 | // as input, otherwise the screen bitmap. |
| 191 | // All progs >= glsl_program_mb2sc using the screen bitmap |
| 192 | // as output, otherwise the mame bitmap. |
| 193 | int glsl_vid_attributes;// glsl brightness, contrast and gamma for RGB bitmaps |
| 194 | int usetexturerect; // use ARB_texture_rectangle for non-power-of-2, general use |
| 195 | |
| 196 | int init_context; // initialize context before next draw |
| 197 | |
| 198 | int totalColors; // total colors from machine/sdl_window_config/sdl_window_info |
| 199 | |
| 200 | // Static vars from draogl_window_dra |
| 201 | INT32 old_blitwidth; |
| 202 | INT32 old_blitheight; |
| 203 | INT32 surf_w; |
| 204 | INT32 surf_h; |
| 205 | GLfloat texVerticex[8]; |
| 206 | }; |
| 207 | |
| 208 | |
| 209 | //============================================================ |
| 155 | 210 | // INLINES |
| 156 | 211 | //============================================================ |
| 157 | 212 | |
| r2959 | r2960 | |
| 188 | 243 | } |
| 189 | 244 | } |
| 190 | 245 | |
| 191 | | #if 0 |
| 192 | | INLINE int better_mode(int width0, int height0, int width1, int height1, float desired_aspect) |
| 193 | | { |
| 194 | | float aspect0 = (float)width0 / (float)height0; |
| 195 | | float aspect1 = (float)width1 / (float)height1; |
| 196 | | return (fabs(desired_aspect - aspect0) < fabs(desired_aspect - aspect1)) ? 0 : 1; |
| 197 | | } |
| 198 | | #endif |
| 199 | | |
| 200 | 246 | INLINE UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr) |
| 201 | 247 | { |
| 202 | 248 | /* original equations: |
| r2959 | r2960 | |
| 246 | 292 | // core functions |
| 247 | 293 | |
| 248 | 294 | static void drawogl_exit(void); |
| 249 | | static int drawogl_window_init(sdl_window_info *window); |
| 295 | static int drawogl_window_create(sdl_window_info *window, int width, int height); |
| 296 | static void drawogl_window_resize(sdl_window_info *window, int width, int height); |
| 250 | 297 | static void drawogl_window_destroy(sdl_window_info *window); |
| 251 | 298 | static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 252 | 299 | static const render_primitive_list *drawogl_window_get_primitives(sdl_window_info *window); |
| 253 | 300 | static void drawogl_destroy_all_textures(sdl_window_info *window); |
| 301 | static void drawogl_window_clear(sdl_window_info *window); |
| 254 | 302 | |
| 303 | |
| 304 | |
| 255 | 305 | // OGL 1.3 |
| 256 | 306 | static PFNGLACTIVETEXTUREPROC pfn_glActiveTexture = NULL; |
| 257 | 307 | |
| r2959 | r2960 | |
| 333 | 383 | //============================================================ |
| 334 | 384 | |
| 335 | 385 | static int shown_video_info = 0; |
| 386 | static int dll_loaded = 0; |
| 336 | 387 | |
| 337 | 388 | //============================================================ |
| 338 | 389 | // drawogl_init |
| r2959 | r2960 | |
| 342 | 393 | { |
| 343 | 394 | // fill in the callbacks |
| 344 | 395 | callbacks->exit = drawogl_exit; |
| 345 | | callbacks->window_init = drawogl_window_init; |
| 396 | callbacks->window_create = drawogl_window_create; |
| 397 | callbacks->window_resize = drawogl_window_resize; |
| 346 | 398 | callbacks->window_get_primitives = drawogl_window_get_primitives; |
| 347 | 399 | callbacks->window_draw = drawogl_window_draw; |
| 348 | 400 | callbacks->window_destroy = drawogl_window_destroy; |
| 349 | 401 | callbacks->window_destroy_all_textures = drawogl_destroy_all_textures; |
| 402 | callbacks->window_clear = drawogl_window_clear; |
| 350 | 403 | |
| 351 | | #if SDL_MULTIMON |
| 404 | dll_loaded = 0; |
| 405 | |
| 406 | #if SDL_VERSION_ATLEAST(1,3,0) |
| 352 | 407 | mame_printf_verbose("Using SDL multi-window OpenGL driver (SDL 1.3+)\n"); |
| 353 | 408 | #else |
| 354 | 409 | mame_printf_verbose("Using SDL single-window OpenGL driver (SDL 1.2)\n"); |
| r2959 | r2960 | |
| 386 | 441 | #endif |
| 387 | 442 | } |
| 388 | 443 | |
| 389 | | void drawogl_init_ogl_context(void) |
| 444 | //============================================================ |
| 445 | // Load GL library |
| 446 | //============================================================ |
| 447 | |
| 448 | static void load_gl_lib(void) |
| 390 | 449 | { |
| 391 | | // do some one-time OpenGL setup |
| 392 | | glShadeModel(GL_SMOOTH); |
| 393 | | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 394 | | glClearDepth(1.0f); |
| 395 | | glEnable(GL_DEPTH_TEST); |
| 396 | | glDepthFunc(GL_LEQUAL); |
| 397 | | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
| 450 | #ifdef USE_DISPATCH_GL |
| 451 | if (!dll_loaded) |
| 452 | { |
| 453 | /* |
| 454 | * directfb and and x11 use this env var |
| 455 | * SDL_VIDEO_GL_DRIVER |
| 456 | */ |
| 457 | const char *e; |
| 458 | |
| 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 |
| 467 | { |
| 468 | fatalerror("Unable to load default library: %s\n", e); |
| 469 | } |
| 470 | mame_printf_verbose("Loaded opengl shared library: %s\n", e ? e : "<default>"); |
| 471 | gl_dispatch = auto_malloc(sizeof(osd_gl_dispatch)); |
| 472 | dll_loaded=1; |
| 473 | } |
| 474 | #endif |
| 398 | 475 | } |
| 399 | 476 | |
| 400 | 477 | //============================================================ |
| 401 | | // drawogl_window_init |
| 478 | // drawogl_window_create |
| 402 | 479 | //============================================================ |
| 403 | 480 | |
| 404 | | static int drawogl_window_init(sdl_window_info *window) |
| 481 | static int drawogl_window_create(sdl_window_info *window, int width, int height) |
| 405 | 482 | { |
| 406 | | sdl_info *sdl; |
| 483 | sdl_info *sdl = window->dxdata; |
| 407 | 484 | char *extstr; |
| 408 | 485 | char *vendor; |
| 409 | 486 | int has_and_allow_texturerect = 0; |
| 410 | | |
| 487 | |
| 411 | 488 | // allocate memory for our structures |
| 412 | 489 | sdl = malloc(sizeof(*sdl)); |
| 413 | 490 | memset(sdl, 0, sizeof(*sdl)); |
| 414 | | sdl->totalColors = window->totalColors; |
| 415 | 491 | |
| 416 | 492 | window->dxdata = sdl; |
| 417 | | window->initialized = 0; |
| 418 | 493 | |
| 494 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 495 | window->extra_flags = (window->fullscreen ? |
| 496 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE); |
| 497 | window->extra_flags |= SDL_WINDOW_OPENGL; |
| 498 | |
| 499 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 500 | load_gl_lib(); |
| 501 | |
| 502 | // create the SDL window |
| 503 | SDL_SelectVideoDisplay(window->monitor->handle); |
| 504 | SDL_SetFullscreenDisplayMode(NULL); // Use desktop |
| 505 | 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) ) |
| 509 | { |
| 510 | fprintf(stderr, "OpenGL not supported on this driver!\n"); |
| 511 | return 1; |
| 512 | } |
| 513 | #endif |
| 514 | SDL_ShowWindow(window->window_id); |
| 515 | SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 516 | SDL_RaiseWindow(window->window_id); |
| 517 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 518 | |
| 519 | sdl->gl_context_id = SDL_GL_CreateContext(window->window_id); |
| 520 | |
| 521 | #else |
| 522 | window->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 523 | window->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; |
| 524 | |
| 525 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 526 | #if (SDL_VERSION_ATLEAST(1,2,10)) |
| 527 | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, |
| 528 | options_get_bool(mame_options(), SDLOPTION_WAITVSYNC) ? 1 : 0); |
| 529 | #endif |
| 530 | |
| 531 | load_gl_lib(); |
| 532 | |
| 533 | // create the SDL surface (which creates the window in windowed mode) |
| 534 | sdl->sdlsurf = SDL_SetVideoMode(width, height, |
| 535 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 536 | |
| 537 | if (!sdl->sdlsurf) |
| 538 | return 1; |
| 539 | |
| 540 | window->width = sdl->sdlsurf->w; |
| 541 | window->height = sdl->sdlsurf->h; |
| 542 | |
| 543 | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) ) |
| 544 | { |
| 545 | fprintf(stderr, "OpenGL not supported on this driver!\n"); |
| 546 | return 1; |
| 547 | } |
| 548 | |
| 549 | // set the window title |
| 550 | SDL_WM_SetCaption(window->title, "SDLMAME"); |
| 551 | |
| 552 | #endif |
| 553 | sdl->totalColors = window->totalColors; |
| 554 | sdl->old_blitwidth = 0; |
| 555 | sdl->old_blitheight = 0; |
| 556 | sdl->blittimer = 0; |
| 557 | sdl->surf_w = 0; |
| 558 | sdl->surf_h = 0; |
| 559 | |
| 560 | sdl->initialized = 0; |
| 561 | |
| 419 | 562 | // in case any textures try to come up before these are validated, |
| 420 | 563 | // OpenGL guarantees all implementations can handle something this size. |
| 421 | 564 | sdl->texture_max_width = 64; |
| r2959 | r2960 | |
| 523 | 666 | |
| 524 | 667 | if (strstr(extstr, "GL_EXT_framebuffer_object")) |
| 525 | 668 | { |
| 526 | | sdl->usefbo = 1; |
| 669 | sdl->usefbo = 1; |
| 527 | 670 | if (!shown_video_info) |
| 528 | 671 | { |
| 529 | 672 | if(sdl->usefbo) |
| r2959 | r2960 | |
| 570 | 713 | |
| 571 | 714 | shown_video_info = 1; |
| 572 | 715 | |
| 573 | | drawogl_init_ogl_context(); |
| 716 | sdl->init_context = 0; |
| 574 | 717 | |
| 575 | 718 | return 0; |
| 576 | 719 | } |
| 577 | 720 | |
| 578 | 721 | //============================================================ |
| 722 | // drawogl_window_resize |
| 723 | //============================================================ |
| 724 | |
| 725 | static void drawogl_window_resize(sdl_window_info *window, int width, int height) |
| 726 | { |
| 727 | sdl_info *sdl = window->dxdata; |
| 728 | |
| 729 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 730 | SDL_SetWindowSize(window->window_id, width, height); |
| 731 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 732 | |
| 733 | //FIXME: no idea why, but this is necessary to avoid crashes with numscreen>1 |
| 734 | SDL_GL_DeleteContext(sdl->gl_context_id); |
| 735 | sdl->gl_context_id = SDL_GL_CreateContext(window->window_id); |
| 736 | #else |
| 737 | SDL_FreeSurface(sdl->sdlsurf); |
| 738 | |
| 739 | sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 740 | SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 741 | window->width = sdl->sdlsurf->w; |
| 742 | window->height = sdl->sdlsurf->h; |
| 743 | |
| 744 | #endif |
| 745 | sdl->init_context = 0; |
| 746 | |
| 747 | } |
| 748 | |
| 749 | //============================================================ |
| 579 | 750 | // drawogl_window_get_primitives |
| 580 | 751 | //============================================================ |
| 581 | 752 | |
| 582 | 753 | static const render_primitive_list *drawogl_window_get_primitives(sdl_window_info *window) |
| 583 | 754 | { |
| 584 | | sdl_info *sdl = window->dxdata; |
| 585 | | if ((video_config.windowed) || (video_config.switchres)) |
| 755 | if ((!window->fullscreen) || (video_config.switchres)) |
| 586 | 756 | { |
| 587 | | sdlwindow_blit_surface_size(window, window->sdlsurf->w, window->sdlsurf->h); |
| 757 | sdlwindow_blit_surface_size(window, window->width, window->height); |
| 588 | 758 | } |
| 589 | 759 | else |
| 590 | 760 | { |
| 591 | 761 | sdlwindow_blit_surface_size(window, window->monitor->center_width, window->monitor->center_height); |
| 592 | 762 | } |
| 593 | | render_target_set_bounds(window->target, sdl->blitwidth, sdl->blitheight, sdlvideo_monitor_get_aspect(window->monitor)); |
| 763 | render_target_set_bounds(window->target, window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor)); |
| 594 | 764 | return render_target_get_primitives(window->target); |
| 595 | 765 | } |
| 596 | 766 | |
| r2959 | r2960 | |
| 794 | 964 | |
| 795 | 965 | if ( sdl->useglsl ) |
| 796 | 966 | { |
| 797 | | sdl->useglsl = !glsl_shader_init(sdl); |
| 967 | sdl->glsl = glsl_shader_init(); |
| 968 | sdl->useglsl = (sdl->glsl != NULL ? 1 : 0); |
| 798 | 969 | |
| 799 | 970 | if ( ! sdl->useglsl ) |
| 800 | 971 | { |
| r2959 | r2960 | |
| 844 | 1015 | break; |
| 845 | 1016 | } |
| 846 | 1017 | |
| 847 | | if ( glsl_shader_add_mamebm(sdl, video_config.glsl_shader_mamebm[i], sdl->glsl_program_num) ) |
| 1018 | if ( glsl_shader_add_mamebm(sdl->glsl, video_config.glsl_shader_mamebm[i], sdl->glsl_program_num) ) |
| 848 | 1019 | { |
| 849 | 1020 | mame_printf_error("OpenGL: GLSL loading mame bitmap shader %d failed (%s)\n", |
| 850 | 1021 | i, video_config.glsl_shader_mamebm[i]); |
| r2959 | r2960 | |
| 867 | 1038 | |
| 868 | 1039 | for(i=0; sdl->usefbo && sdl->glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++) |
| 869 | 1040 | { |
| 870 | | if ( glsl_shader_add_scrn(sdl, video_config.glsl_shader_scrn[i], |
| 1041 | if ( glsl_shader_add_scrn(sdl->glsl, video_config.glsl_shader_scrn[i], |
| 871 | 1042 | sdl->glsl_program_num-1-sdl->glsl_program_mb2sc) ) |
| 872 | 1043 | { |
| 873 | 1044 | mame_printf_error("OpenGL: GLSL loading screen bitmap shader %d failed (%s)\n", |
| r2959 | r2960 | |
| 928 | 1099 | render_primitive *prim; |
| 929 | 1100 | texture_info *texture=NULL; |
| 930 | 1101 | float vofs, hofs; |
| 931 | | static INT32 old_blitwidth = 0, old_blitheight = 0; |
| 932 | | static INT32 blittimer = 0; |
| 933 | | static INT32 surf_w = 0, surf_h = 0; |
| 934 | | static GLfloat texVerticex[8]; |
| 935 | | int pendingPrimitive=GL_NO_PRIMITIVE, curPrimitive=GL_NO_PRIMITIVE; |
| 1102 | int pendingPrimitive=GL_NO_PRIMITIVE, curPrimitive=GL_NO_PRIMITIVE; |
| 936 | 1103 | |
| 937 | 1104 | if (video_config.novideo) |
| 938 | 1105 | { |
| 939 | 1106 | return 0; |
| 940 | 1107 | } |
| 941 | 1108 | |
| 1109 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1110 | //SDL_SelectRenderer(window->window_id); |
| 1111 | SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id); |
| 1112 | #endif |
| 1113 | if (sdl->init_context) |
| 1114 | { |
| 1115 | // do some one-time OpenGL setup |
| 1116 | glShadeModel(GL_SMOOTH); |
| 1117 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1118 | glClearDepth(1.0f); |
| 1119 | glEnable(GL_DEPTH_TEST); |
| 1120 | glDepthFunc(GL_LEQUAL); |
| 1121 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
| 1122 | } |
| 942 | 1123 | // only clear if the geometry changes (and for 2 frames afterward to clear double and triple buffers) |
| 943 | | if ((blittimer > 0) || (video_config.isvector)) |
| 1124 | if ((sdl->blittimer > 0) || (video_config.isvector)) |
| 944 | 1125 | { |
| 945 | 1126 | glClear(GL_COLOR_BUFFER_BIT); |
| 946 | | blittimer--; |
| 1127 | sdl->blittimer--; |
| 947 | 1128 | } |
| 948 | 1129 | |
| 949 | | if ((old_blitwidth != sdl->blitwidth) || (old_blitheight != sdl->blitheight)) |
| 1130 | if (sdl->init_context || (sdl->old_blitwidth != window->blitwidth) || (sdl->old_blitheight != window->blitheight)) |
| 950 | 1131 | { |
| 951 | 1132 | glClear(GL_COLOR_BUFFER_BIT); |
| 952 | 1133 | |
| 953 | | old_blitwidth = sdl->blitwidth; |
| 954 | | old_blitheight = sdl->blitheight; |
| 1134 | sdl->old_blitwidth = window->blitwidth; |
| 1135 | sdl->old_blitheight = window->blitheight; |
| 955 | 1136 | |
| 956 | | blittimer = 2; |
| 1137 | sdl->blittimer = 2; |
| 957 | 1138 | } |
| 958 | 1139 | |
| 959 | | if ( !window->initialized || |
| 960 | | window->sdlsurf->w!= surf_w || window->sdlsurf->h!= surf_h ) |
| 1140 | if ( !sdl->initialized || |
| 1141 | window->width!= sdl->surf_w || window->height!= sdl->surf_h ) |
| 961 | 1142 | { |
| 962 | | if ( !window->initialized ) |
| 1143 | if ( !sdl->initialized ) |
| 963 | 1144 | { |
| 964 | 1145 | loadGLExtensions(sdl); |
| 965 | 1146 | } |
| 966 | 1147 | |
| 967 | | surf_w=window->sdlsurf->w; |
| 968 | | surf_h=window->sdlsurf->h; |
| 1148 | sdl->surf_w=window->width; |
| 1149 | sdl->surf_h=window->height; |
| 969 | 1150 | |
| 970 | 1151 | // we're doing nothing 3d, so the Z-buffer is currently not interesting |
| 971 | 1152 | glDisable(GL_DEPTH_TEST); |
| r2959 | r2960 | |
| 1006 | 1187 | // |_________| |
| 1007 | 1188 | // (0,h) (w,h) |
| 1008 | 1189 | |
| 1009 | | glViewport(0.0, 0.0, (GLsizei)window->sdlsurf->w, (GLsizei)window->sdlsurf->h); |
| 1190 | glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height); |
| 1010 | 1191 | glMatrixMode(GL_PROJECTION); |
| 1011 | 1192 | glLoadIdentity(); |
| 1012 | | glOrtho(0.0, (GLdouble)window->sdlsurf->w, (GLdouble)window->sdlsurf->h, 0.0, 0.0, -1.0); |
| 1193 | glOrtho(0.0, (GLdouble)window->width, (GLdouble)window->height, 0.0, 0.0, -1.0); |
| 1013 | 1194 | glMatrixMode(GL_MODELVIEW); |
| 1014 | 1195 | glLoadIdentity(); |
| 1015 | 1196 | |
| 1016 | | if ( ! window->initialized ) |
| 1197 | if ( ! sdl->initialized ) |
| 1017 | 1198 | { |
| 1018 | 1199 | glEnableClientState(GL_VERTEX_ARRAY); |
| 1019 | | glVertexPointer(2, GL_FLOAT, 0, texVerticex); // no VBO, since it's too volatile |
| 1200 | glVertexPointer(2, GL_FLOAT, 0, sdl->texVerticex); // no VBO, since it's too volatile |
| 1020 | 1201 | |
| 1021 | | window->initialized = 1; |
| 1202 | sdl->initialized = 1; |
| 1022 | 1203 | } |
| 1023 | 1204 | } |
| 1024 | 1205 | |
| r2959 | r2960 | |
| 1029 | 1210 | { |
| 1030 | 1211 | int ch, cw; |
| 1031 | 1212 | |
| 1032 | | if ((!video_config.windowed) && (!video_config.switchres)) |
| 1213 | if ((window->fullscreen) && (!video_config.switchres)) |
| 1033 | 1214 | { |
| 1034 | 1215 | ch = window->monitor->center_height; |
| 1035 | 1216 | cw = window->monitor->center_width; |
| 1036 | 1217 | } |
| 1037 | 1218 | else |
| 1038 | 1219 | { |
| 1039 | | ch = window->sdlsurf->h; |
| 1040 | | cw = window->sdlsurf->w; |
| 1220 | ch = window->height; |
| 1221 | cw = window->width; |
| 1041 | 1222 | } |
| 1042 | 1223 | |
| 1043 | 1224 | if (video_config.centerv) |
| 1044 | 1225 | { |
| 1045 | | vofs = (ch - sdl->blitheight) / 2.0f; |
| 1226 | vofs = (ch - window->blitheight) / 2.0f; |
| 1046 | 1227 | } |
| 1047 | 1228 | if (video_config.centerh) |
| 1048 | 1229 | { |
| 1049 | | hofs = (cw - sdl->blitwidth) / 2.0f; |
| 1230 | hofs = (cw - window->blitwidth) / 2.0f; |
| 1050 | 1231 | } |
| 1051 | 1232 | } |
| 1052 | 1233 | |
| r2959 | r2960 | |
| 1122 | 1303 | if ( i==sdl->glsl_program_mb2sc ) |
| 1123 | 1304 | { |
| 1124 | 1305 | // i==sdl->glsl_program_mb2sc -> transformation mamebm->scrn |
| 1125 | | texVerticex[0]=prim->bounds.x0 + hofs; |
| 1126 | | texVerticex[1]=prim->bounds.y0 + vofs; |
| 1127 | | texVerticex[2]=prim->bounds.x1 + hofs; |
| 1128 | | texVerticex[3]=prim->bounds.y0 + vofs; |
| 1129 | | texVerticex[4]=prim->bounds.x1 + hofs; |
| 1130 | | texVerticex[5]=prim->bounds.y1 + vofs; |
| 1131 | | texVerticex[6]=prim->bounds.x0 + hofs; |
| 1132 | | texVerticex[7]=prim->bounds.y1 + vofs; |
| 1306 | sdl->texVerticex[0]=prim->bounds.x0 + hofs; |
| 1307 | sdl->texVerticex[1]=prim->bounds.y0 + vofs; |
| 1308 | sdl->texVerticex[2]=prim->bounds.x1 + hofs; |
| 1309 | sdl->texVerticex[3]=prim->bounds.y0 + vofs; |
| 1310 | sdl->texVerticex[4]=prim->bounds.x1 + hofs; |
| 1311 | sdl->texVerticex[5]=prim->bounds.y1 + vofs; |
| 1312 | sdl->texVerticex[6]=prim->bounds.x0 + hofs; |
| 1313 | sdl->texVerticex[7]=prim->bounds.y1 + vofs; |
| 1133 | 1314 | } else { |
| 1134 | 1315 | // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions |
| 1135 | | texVerticex[0]=(GLfloat)0.0; |
| 1136 | | texVerticex[1]=(GLfloat)0.0; |
| 1137 | | texVerticex[2]=(GLfloat)window->sdlsurf->w; |
| 1138 | | texVerticex[3]=(GLfloat)0.0; |
| 1139 | | texVerticex[4]=(GLfloat)window->sdlsurf->w; |
| 1140 | | texVerticex[5]=(GLfloat)window->sdlsurf->h; |
| 1141 | | texVerticex[6]=(GLfloat)0.0; |
| 1142 | | texVerticex[7]=(GLfloat)window->sdlsurf->h; |
| 1316 | sdl->texVerticex[0]=(GLfloat)0.0; |
| 1317 | sdl->texVerticex[1]=(GLfloat)0.0; |
| 1318 | sdl->texVerticex[2]=(GLfloat)window->width; |
| 1319 | sdl->texVerticex[3]=(GLfloat)0.0; |
| 1320 | sdl->texVerticex[4]=(GLfloat)window->width; |
| 1321 | sdl->texVerticex[5]=(GLfloat)window->height; |
| 1322 | sdl->texVerticex[6]=(GLfloat)0.0; |
| 1323 | sdl->texVerticex[7]=(GLfloat)window->height; |
| 1143 | 1324 | } |
| 1144 | 1325 | |
| 1145 | 1326 | if(i>0) // first fetch already done |
| r2959 | r2960 | |
| 1149 | 1330 | glDrawArrays(GL_QUADS, 0, 4); |
| 1150 | 1331 | } |
| 1151 | 1332 | } else { |
| 1152 | | texVerticex[0]=prim->bounds.x0 + hofs; |
| 1153 | | texVerticex[1]=prim->bounds.y0 + vofs; |
| 1154 | | texVerticex[2]=prim->bounds.x1 + hofs; |
| 1155 | | texVerticex[3]=prim->bounds.y0 + vofs; |
| 1156 | | texVerticex[4]=prim->bounds.x1 + hofs; |
| 1157 | | texVerticex[5]=prim->bounds.y1 + vofs; |
| 1158 | | texVerticex[6]=prim->bounds.x0 + hofs; |
| 1159 | | texVerticex[7]=prim->bounds.y1 + vofs; |
| 1333 | sdl->texVerticex[0]=prim->bounds.x0 + hofs; |
| 1334 | sdl->texVerticex[1]=prim->bounds.y0 + vofs; |
| 1335 | sdl->texVerticex[2]=prim->bounds.x1 + hofs; |
| 1336 | sdl->texVerticex[3]=prim->bounds.y0 + vofs; |
| 1337 | sdl->texVerticex[4]=prim->bounds.x1 + hofs; |
| 1338 | sdl->texVerticex[5]=prim->bounds.y1 + vofs; |
| 1339 | sdl->texVerticex[6]=prim->bounds.x0 + hofs; |
| 1340 | sdl->texVerticex[7]=prim->bounds.y1 + vofs; |
| 1160 | 1341 | |
| 1161 | 1342 | glDrawArrays(GL_QUADS, 0, 4); |
| 1162 | 1343 | } |
| r2959 | r2960 | |
| 1177 | 1358 | } |
| 1178 | 1359 | |
| 1179 | 1360 | osd_lock_release(window->primlist->lock); |
| 1361 | sdl->init_context = 0; |
| 1180 | 1362 | |
| 1363 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 1181 | 1364 | SDL_GL_SwapBuffers(); |
| 1365 | #else |
| 1366 | SDL_GL_SwapWindow(window->window_id); |
| 1367 | #endif |
| 1182 | 1368 | return 0; |
| 1183 | 1369 | } |
| 1184 | 1370 | |
| r2959 | r2960 | |
| 1369 | 1555 | if (sdl == NULL) |
| 1370 | 1556 | return; |
| 1371 | 1557 | |
| 1558 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 1559 | SDL_GL_DeleteContext(sdl->gl_context_id); |
| 1560 | SDL_DestroyWindow(window->window_id); |
| 1561 | #else |
| 1562 | if (sdl->sdlsurf) |
| 1563 | { |
| 1564 | SDL_FreeSurface(sdl->sdlsurf); |
| 1565 | sdl->sdlsurf = NULL; |
| 1566 | } |
| 1567 | #endif |
| 1568 | |
| 1372 | 1569 | // free the memory in the window |
| 1373 | 1570 | |
| 1374 | 1571 | drawogl_destroy_all_textures(window); |
| r2959 | r2960 | |
| 1680 | 1877 | int glsl_shader_type_rgb32 = ( sdl->glsl_vid_attributes ) ? GLSL_SHADER_TYPE_RGB32_DIRECT : GLSL_SHADER_TYPE_RGB32_LUT; |
| 1681 | 1878 | int glsl_shader_type, i; |
| 1682 | 1879 | int lut_texture_width; |
| 1683 | | int surf_w_pow2 = get_valid_pow2_value (window->sdlsurf->w, texture->texpow2); |
| 1684 | | int surf_h_pow2 = get_valid_pow2_value (window->sdlsurf->h, texture->texpow2); |
| 1880 | int surf_w_pow2 = get_valid_pow2_value (window->width, texture->texpow2); |
| 1881 | int surf_h_pow2 = get_valid_pow2_value (window->height, texture->texpow2); |
| 1685 | 1882 | |
| 1686 | 1883 | assert ( texture->type==TEXTURE_TYPE_SHADER ); |
| 1687 | 1884 | |
| r2959 | r2960 | |
| 1703 | 1900 | |
| 1704 | 1901 | case SDL_TEXFORMAT_PALETTE16: |
| 1705 | 1902 | glsl_shader_type = GLSL_SHADER_TYPE_IDX16; |
| 1706 | | texture->lut_table_width = sdl->totalColors; |
| 1903 | texture->lut_table_width = sdl->totalColors; |
| 1707 | 1904 | break; |
| 1708 | 1905 | |
| 1709 | 1906 | default: |
| r2959 | r2960 | |
| 1829 | 2026 | if ( i>sdl->glsl_program_mb2sc ) |
| 1830 | 2027 | { |
| 1831 | 2028 | { |
| 1832 | | GLfloat screen_texture_sz[2] = { (GLfloat)window->sdlsurf->w, (GLfloat)window->sdlsurf->h }; |
| 2029 | GLfloat screen_texture_sz[2] = { (GLfloat)window->width, (GLfloat)window->height }; |
| 1833 | 2030 | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "screen_texture_sz"); |
| 1834 | 2031 | pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0])); |
| 1835 | 2032 | GL_CHECK_ERROR_NORMAL(); |
| r2959 | r2960 | |
| 1889 | 2086 | } |
| 1890 | 2087 | |
| 1891 | 2088 | mame_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n", |
| 1892 | | window->sdlsurf->w, window->sdlsurf->h, surf_w_pow2, surf_h_pow2); |
| 2089 | window->width, window->height, surf_w_pow2, surf_h_pow2); |
| 1893 | 2090 | } |
| 1894 | 2091 | |
| 1895 | 2092 | if ( !(sdl->glsl_vid_attributes && texture->format!=SDL_TEXFORMAT_PALETTE16) ) |
| r2959 | r2960 | |
| 2374 | 2571 | } |
| 2375 | 2572 | } else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc ) |
| 2376 | 2573 | { |
| 2377 | | int surf_w_pow2 = get_valid_pow2_value (window->sdlsurf->w, texture->texpow2); |
| 2378 | | int surf_h_pow2 = get_valid_pow2_value (window->sdlsurf->h, texture->texpow2); |
| 2574 | int surf_w_pow2 = get_valid_pow2_value (window->width, texture->texpow2); |
| 2575 | int surf_h_pow2 = get_valid_pow2_value (window->height, texture->texpow2); |
| 2379 | 2576 | |
| 2380 | 2577 | ustart = 0.0f; |
| 2381 | | ustop = (float)(window->sdlsurf->w) / (float)surf_w_pow2; |
| 2578 | ustop = (float)(window->width) / (float)surf_w_pow2; |
| 2382 | 2579 | vstart = 0.0f; |
| 2383 | | vstop = (float)(window->sdlsurf->h) / (float)surf_h_pow2; |
| 2580 | vstop = (float)(window->height) / (float)surf_h_pow2; |
| 2384 | 2581 | } else { |
| 2385 | 2582 | assert(0); // ?? |
| 2386 | 2583 | } |
| r2959 | r2960 | |
| 2466 | 2663 | } else if ( shaderIdx==sdl->glsl_program_mb2sc ) |
| 2467 | 2664 | { |
| 2468 | 2665 | assert ( sdl->glsl_program_mb2sc < sdl->glsl_program_num-1 ); |
| 2469 | | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->sdlsurf->w, (GLsizei)window->sdlsurf->h) |
| 2666 | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) |
| 2470 | 2667 | GL_CHECK_ERROR_NORMAL(); |
| 2471 | 2668 | } |
| 2472 | 2669 | glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn .. |
| r2959 | r2960 | |
| 2476 | 2673 | |
| 2477 | 2674 | if ( sdl->glsl_program_mb2sc == sdl->glsl_program_num-1 ) |
| 2478 | 2675 | { |
| 2479 | | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->sdlsurf->w, (GLsizei)window->sdlsurf->h) |
| 2676 | glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height) |
| 2480 | 2677 | GL_CHECK_ERROR_NORMAL(); |
| 2481 | 2678 | } |
| 2482 | 2679 | |
| r2959 | r2960 | |
| 2510 | 2707 | |
| 2511 | 2708 | if (container!=NULL) |
| 2512 | 2709 | { |
| 2513 | | vid_attributes[0] = render_container_get_gamma(container); |
| 2514 | | vid_attributes[1] = render_container_get_contrast(container); |
| 2515 | | vid_attributes[2] = render_container_get_brightness(container); |
| 2710 | render_container_user_settings settings; |
| 2711 | |
| 2712 | render_container_get_user_settings(container, &settings); |
| 2713 | |
| 2714 | vid_attributes[0] = options_get_float(mame_options(), OPTION_GAMMA); |
| 2715 | vid_attributes[1] = options_get_float(mame_options(), OPTION_CONTRAST); |
| 2716 | vid_attributes[2] = options_get_float(mame_options(), OPTION_BRIGHTNESS); |
| 2516 | 2717 | vid_attributes[3] = 0.0f; |
| 2517 | 2718 | uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[shaderIdx], "vid_attributes"); |
| 2518 | 2719 | pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx])); |
| r2959 | r2960 | |
| 2648 | 2849 | |
| 2649 | 2850 | static void drawogl_destroy_all_textures(sdl_window_info *window) |
| 2650 | 2851 | { |
| 2852 | sdl_info *sdl = window->dxdata; |
| 2651 | 2853 | int lock=FALSE; |
| 2652 | 2854 | |
| 2653 | | if ( ! window->initialized ) |
| 2855 | if ( ! sdl->initialized ) |
| 2654 | 2856 | { |
| 2655 | 2857 | return; |
| 2656 | 2858 | } |
| r2959 | r2960 | |
| 2724 | 2926 | |
| 2725 | 2927 | if ( sdl->useglsl ) |
| 2726 | 2928 | { |
| 2727 | | glsl_shader_free(sdl); |
| 2929 | glsl_shader_free(sdl->glsl); |
| 2930 | sdl->glsl = NULL; |
| 2728 | 2931 | } |
| 2729 | 2932 | |
| 2730 | | window->initialized = 0; |
| 2933 | sdl->initialized = 0; |
| 2731 | 2934 | } |
| 2732 | 2935 | exit: |
| 2733 | 2936 | if(lock) { osd_lock_release(window->primlist->lock); } |
| r2959 | r2960 | |
| 2737 | 2940 | // TEXCOPY FUNCS |
| 2738 | 2941 | //============================================================ |
| 2739 | 2942 | |
| 2943 | static void drawogl_window_clear(sdl_window_info *window) |
| 2944 | { |
| 2945 | sdl_info *sdl = window->dxdata; |
| 2946 | |
| 2947 | //FIXME: Handled in drawogl_window_draw as well |
| 2948 | sdl->blittimer = 2; |
| 2949 | } |
| 2950 | |
| 2951 | |
| 2952 | //============================================================ |
| 2953 | // TEXCOPY FUNCS |
| 2954 | //============================================================ |
| 2955 | |
| 2740 | 2956 | #include "texcopy.c" |
| 2741 | 2957 | |
| 2742 | 2958 | //============================================================ |
src/osd/sdl/sound.c
| r2959 | r2960 | |
| 64 | 64 | static int buffer_overflows; |
| 65 | 65 | |
| 66 | 66 | // debugging |
| 67 | | #if LOG_SOUND |
| 68 | | #define sound_log stderr |
| 69 | | #endif |
| 67 | static FILE *sound_log; |
| 70 | 68 | |
| 69 | |
| 71 | 70 | // sound enable |
| 72 | 71 | static int snd_enabled; |
| 73 | 72 | |
| r2959 | r2960 | |
| 89 | 88 | //============================================================ |
| 90 | 89 | void sdlaudio_init(running_machine *machine) |
| 91 | 90 | { |
| 92 | | #if LOG_SOUND |
| 93 | | sound_log = fopen(SDL_SOUND_LOG, "w"); |
| 94 | | #endif |
| 91 | if (LOG_SOUND) |
| 92 | sound_log = fopen(SDL_SOUND_LOG, "w"); |
| 95 | 93 | |
| 96 | 94 | // skip if sound disabled |
| 97 | 95 | if (machine->sample_rate != 0) |
| r2959 | r2960 | |
| 127 | 125 | if (buffer_overflows || buffer_underflows) |
| 128 | 126 | mame_printf_verbose("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); |
| 129 | 127 | |
| 130 | | #if LOG_SOUND |
| 131 | | if (sound_log) |
| 128 | if (LOG_SOUND) |
| 129 | { |
| 132 | 130 | fprintf(sound_log, "Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows); |
| 133 | | fclose(sound_log); |
| 134 | | #endif |
| 131 | fclose(sound_log); |
| 132 | } |
| 135 | 133 | } |
| 136 | 134 | |
| 137 | 135 | //============================================================ |
| r2959 | r2960 | |
| 152 | 150 | while (((pstart >= lstart) && (pstart <= lend)) || |
| 153 | 151 | ((pend >= lstart) && (pend <= lend))) |
| 154 | 152 | { |
| 155 | | /* #ifdef SDLMAME_WIN32 |
| 156 | | Sleep(0); |
| 157 | | #else |
| 158 | | sleep(0); |
| 159 | | #endif*/ |
| 160 | | |
| 161 | 153 | pstart = stream_playpos; |
| 162 | 154 | pend = pstart + sdl_xfer_samples; |
| 163 | 155 | } |
| r2959 | r2960 | |
| 185 | 177 | *buffer1 = &stream_buffer[offset]; |
| 186 | 178 | } |
| 187 | 179 | |
| 188 | | #if LOG_SOUND |
| 189 | | fprintf(sound_log, "locking %ld bytes at offset %ld (total %d, playpos %d): len1 %ld len2 %ld\n", |
| 180 | if (LOG_SOUND) |
| 181 | fprintf(sound_log, "locking %ld bytes at offset %ld (total %d, playpos %d): len1 %ld len2 %ld\n", |
| 190 | 182 | size, offset, stream_buffer_size, stream_playpos, *length1, *length2); |
| 191 | | #endif |
| 192 | 183 | |
| 193 | 184 | return 0; |
| 194 | 185 | } |
| r2959 | r2960 | |
| 202 | 193 | if (!buf_locked) |
| 203 | 194 | SDL_UnlockAudio(); |
| 204 | 195 | |
| 205 | | #if LOG_SOUND |
| 206 | | fprintf(sound_log, "unlocking\n"); |
| 207 | | #endif |
| 196 | if (LOG_SOUND) |
| 197 | fprintf(sound_log, "unlocking\n"); |
| 198 | |
| 208 | 199 | } |
| 209 | 200 | |
| 210 | 201 | //============================================================ |
| r2959 | r2960 | |
| 246 | 237 | { |
| 247 | 238 | stream_buffer_in -= stream_buffer_size; |
| 248 | 239 | stream_loop = 1; |
| 249 | | #if LOG_SOUND |
| 250 | | fprintf(sound_log, "stream_loop set to 1 (stream_buffer_in looped)\n"); |
| 251 | | #endif |
| 240 | |
| 241 | if (LOG_SOUND) |
| 242 | fprintf(sound_log, "stream_loop set to 1 (stream_buffer_in looped)\n"); |
| 252 | 243 | } |
| 253 | 244 | |
| 254 | 245 | // copy the first chunk |
| r2959 | r2960 | |
| 282 | 273 | { |
| 283 | 274 | int bytes_this_frame = samples_this_frame * sizeof(INT16) * 2; |
| 284 | 275 | int play_position, write_position, stream_in; |
| 285 | | #if LOG_SOUND |
| 286 | | int orig_write; |
| 287 | | #endif |
| 276 | int orig_write; // used in LOG |
| 277 | |
| 288 | 278 | play_position = stream_playpos; |
| 289 | 279 | |
| 290 | 280 | write_position = stream_playpos + ((machine->sample_rate / 50) * sizeof(INT16) * 2); |
| 291 | | #if LOG_SOUND |
| 292 | 281 | orig_write = write_position; |
| 293 | | #endif |
| 294 | 282 | |
| 295 | 283 | if (!stream_in_initialized) |
| 296 | 284 | { |
| 297 | 285 | stream_in = stream_buffer_in = (write_position + stream_buffer_size) / 2; |
| 298 | 286 | |
| 299 | | #if LOG_SOUND |
| 300 | | fprintf(sound_log, "stream_in = %d\n", (int)stream_in); |
| 301 | | fprintf(sound_log, "stream_playpos = %d\n", (int)stream_playpos); |
| 302 | | fprintf(sound_log, "write_position = %d\n", (int)write_position); |
| 303 | | #endif |
| 304 | | |
| 287 | if (LOG_SOUND) |
| 288 | { |
| 289 | fprintf(sound_log, "stream_in = %d\n", (int)stream_in); |
| 290 | fprintf(sound_log, "stream_playpos = %d\n", (int)stream_playpos); |
| 291 | fprintf(sound_log, "write_position = %d\n", (int)write_position); |
| 292 | } |
| 305 | 293 | // start playing |
| 306 | 294 | SDL_PauseAudio(0); |
| 307 | 295 | |
| r2959 | r2960 | |
| 320 | 308 | // if we're between play and write positions, then bump forward, but only in full chunks |
| 321 | 309 | while (stream_in < write_position) |
| 322 | 310 | { |
| 323 | | #if LOG_SOUND |
| 324 | | fprintf(sound_log, "Underflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame); |
| 325 | | #endif |
| 311 | if (LOG_SOUND) |
| 312 | fprintf(sound_log, "Underflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame); |
| 313 | |
| 326 | 314 | buffer_underflows++; |
| 327 | 315 | stream_in += samples_this_frame; |
| 328 | 316 | } |
| r2959 | r2960 | |
| 330 | 318 | // if we're going to overlap the play position, just skip this chunk |
| 331 | 319 | if (stream_in + bytes_this_frame > play_position + stream_buffer_size) |
| 332 | 320 | { |
| 333 | | #if LOG_SOUND |
| 334 | | fprintf(sound_log, "Overflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame); |
| 335 | | #endif |
| 321 | if (LOG_SOUND) |
| 322 | fprintf(sound_log, "Overflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame); |
| 323 | |
| 336 | 324 | buffer_overflows++; |
| 337 | 325 | return; |
| 338 | 326 | } |
| r2959 | r2960 | |
| 342 | 330 | { |
| 343 | 331 | stream_in -= stream_buffer_size; |
| 344 | 332 | stream_loop = 1; |
| 345 | | #if LOG_SOUND |
| 346 | | fprintf(sound_log, "stream_loop set to 1 (stream_in looped)\n"); |
| 347 | | #endif |
| 333 | |
| 334 | if (LOG_SOUND) |
| 335 | fprintf(sound_log, "stream_loop set to 1 (stream_in looped)\n"); |
| 336 | |
| 348 | 337 | } |
| 349 | 338 | |
| 350 | 339 | // now we know where to copy; let's do it |
| r2959 | r2960 | |
| 383 | 372 | |
| 384 | 373 | if (sb_in < (stream_playpos+len)) |
| 385 | 374 | { |
| 386 | | #if LOG_SOUND |
| 387 | | fprintf(sound_log, "Underflow at sdl_callback: SPP=%d SBI=%d(%d) Len=%d\n", (int)stream_playpos, (int)sb_in, (int)stream_buffer_in, (int)len); |
| 388 | | #endif |
| 375 | if (LOG_SOUND) |
| 376 | fprintf(sound_log, "Underflow at sdl_callback: SPP=%d SBI=%d(%d) Len=%d\n", (int)stream_playpos, (int)sb_in, (int)stream_buffer_in, (int)len); |
| 377 | |
| 389 | 378 | return; |
| 390 | 379 | } |
| 391 | 380 | else if ((stream_playpos+len) > stream_buffer_size) |
| r2959 | r2960 | |
| 421 | 410 | { |
| 422 | 411 | stream_playpos -= stream_buffer_size; |
| 423 | 412 | stream_loop = 0; |
| 424 | | #if LOG_SOUND |
| 425 | | fprintf(sound_log, "stream_loop set to 0 (stream_playpos looped)\n"); |
| 426 | | #endif |
| 413 | |
| 414 | if (LOG_SOUND) |
| 415 | fprintf(sound_log, "stream_loop set to 0 (stream_playpos looped)\n"); |
| 427 | 416 | } |
| 428 | 417 | |
| 429 | | #if LOG_SOUND |
| 430 | | fprintf(sound_log, "callback: xfer len1 %d len2 %d, playpos %d\n", |
| 431 | | len1, len2, stream_playpos); |
| 432 | | #endif |
| 418 | if (LOG_SOUND) |
| 419 | fprintf(sound_log, "callback: xfer len1 %d len2 %d, playpos %d\n", |
| 420 | len1, len2, stream_playpos); |
| 433 | 421 | } |
| 434 | 422 | |
| 435 | 423 | |
| r2959 | r2960 | |
| 468 | 456 | initialized_audio = 1; |
| 469 | 457 | snd_enabled = 1; |
| 470 | 458 | |
| 459 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 460 | strncpy(audio_driver, SDL_GetCurrentAudioDriver(), sizeof(audio_driver)); |
| 461 | #else |
| 471 | 462 | SDL_AudioDriverName(audio_driver, sizeof(audio_driver)); |
| 463 | #endif |
| 472 | 464 | mame_printf_verbose("Audio initialized - driver: %s, frequency: %d, " |
| 473 | 465 | "channels: %d, samples: %d\n", audio_driver, |
| 474 | 466 | obtained.freq, obtained.channels, obtained.samples); |
src/osd/sdl/drawsdl.c
| r2959 | r2960 | |
| 38 | 38 | // MACROS |
| 39 | 39 | //============================================================ |
| 40 | 40 | |
| 41 | |
| 41 | 42 | //============================================================ |
| 43 | // TYPES |
| 44 | //============================================================ |
| 45 | |
| 46 | /* sdl_info is the information about SDL for the current screen */ |
| 47 | typedef struct _sdl_info sdl_info; |
| 48 | struct _sdl_info |
| 49 | { |
| 50 | INT32 blittimer; |
| 51 | |
| 52 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 53 | SDL_TextureID texture_id; |
| 54 | #else |
| 55 | // SDL surface |
| 56 | SDL_Surface *sdlsurf; |
| 57 | SDL_Overlay *yuvsurf; |
| 58 | #endif |
| 59 | |
| 60 | // YUV overlay |
| 61 | UINT32 *yuv_lookup; |
| 62 | UINT16 *yuv_bitmap; |
| 63 | int yuv_ovl_width; |
| 64 | int yuv_ovl_height; |
| 65 | }; |
| 66 | |
| 67 | //============================================================ |
| 42 | 68 | // INLINES |
| 43 | 69 | //============================================================ |
| 44 | 70 | |
| r2959 | r2960 | |
| 48 | 74 | |
| 49 | 75 | // core functions |
| 50 | 76 | static void drawsdl_exit(void); |
| 51 | | static int drawsdl_window_init(sdl_window_info *window); |
| 77 | static int drawsdl_window_create(sdl_window_info *window, int width, int height); |
| 78 | static void drawsdl_window_resize(sdl_window_info *window, int width, int height); |
| 52 | 79 | static void drawsdl_window_destroy(sdl_window_info *window); |
| 53 | 80 | static const render_primitive_list *drawsdl_window_get_primitives(sdl_window_info *window); |
| 54 | 81 | static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update); |
| 55 | 82 | static void drawsdl_destroy_all_textures(sdl_window_info *window); |
| 83 | static void drawsdl_window_clear(sdl_window_info *window); |
| 84 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 85 | static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight); |
| 86 | #endif |
| 56 | 87 | |
| 57 | 88 | // soft rendering |
| 58 | 89 | static void drawsdl_rgb888_draw_primitives(const render_primitive *primlist, void *dstdata, UINT32 width, UINT32 height, UINT32 pitch); |
| r2959 | r2960 | |
| 62 | 93 | |
| 63 | 94 | // YUV overlays |
| 64 | 95 | |
| 65 | | static void drawsdl_yuv_init(sdl_window_info *window); |
| 66 | | static void yuv_RGB_to_YV12(UINT16 *bitmap, int bw, sdl_window_info *window); |
| 67 | | static void yuv_RGB_to_YV12X2(UINT16 *bitmap, int bw, sdl_window_info *window); |
| 68 | | static void yuv_RGB_to_YUY2(UINT16 *bitmap, int bw, sdl_window_info *window); |
| 69 | | static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, int bw, sdl_window_info *window); |
| 96 | static void drawsdl_yuv_init(sdl_info *sdl); |
| 97 | static void yuv_RGB_to_YV12(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| 98 | static void yuv_RGB_to_YV12X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| 99 | static void yuv_RGB_to_YUY2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| 100 | static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch); |
| 70 | 101 | |
| 102 | // Static declarations |
| 71 | 103 | |
| 104 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 105 | static int shown_video_info = 0; |
| 106 | static const char *yuv_mode_names[] = { "none", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 107 | #endif |
| 108 | |
| 72 | 109 | //============================================================ |
| 73 | 110 | // drawsdl_init |
| 74 | 111 | //============================================================ |
| r2959 | r2960 | |
| 77 | 114 | { |
| 78 | 115 | // fill in the callbacks |
| 79 | 116 | callbacks->exit = drawsdl_exit; |
| 80 | | callbacks->window_init = drawsdl_window_init; |
| 117 | callbacks->window_create = drawsdl_window_create; |
| 118 | callbacks->window_resize = drawsdl_window_resize; |
| 81 | 119 | callbacks->window_get_primitives = drawsdl_window_get_primitives; |
| 82 | 120 | callbacks->window_draw = drawsdl_window_draw; |
| 83 | 121 | callbacks->window_destroy = drawsdl_window_destroy; |
| 84 | 122 | callbacks->window_destroy_all_textures = drawsdl_destroy_all_textures; |
| 123 | callbacks->window_clear = drawsdl_window_clear; |
| 85 | 124 | |
| 86 | | #if SDL_MULTIMON |
| 125 | #if SDL_VERSION_ATLEAST(1,3,0) |
| 87 | 126 | mame_printf_verbose("Using SDL multi-window soft driver (SDL 1.3+)\n"); |
| 88 | 127 | #else |
| 89 | 128 | mame_printf_verbose("Using SDL single-window soft driver (SDL 1.2)\n"); |
| r2959 | r2960 | |
| 109 | 148 | } |
| 110 | 149 | |
| 111 | 150 | //============================================================ |
| 112 | | // drawsdl_window_init |
| 151 | // setup_texture for window |
| 113 | 152 | //============================================================ |
| 114 | 153 | |
| 115 | | static int drawsdl_window_init(sdl_window_info *window) |
| 154 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 155 | static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight) |
| 116 | 156 | { |
| 117 | | sdl_info *sdl; |
| 157 | sdl_info * sdl = window->dxdata; |
| 158 | // Determine preferred pixelformat and set up yuv if necessary |
| 159 | |
| 160 | if (sdl->yuv_bitmap) |
| 161 | { |
| 162 | free(sdl->yuv_bitmap); |
| 163 | sdl->yuv_bitmap = NULL; |
| 164 | } |
| 165 | |
| 166 | switch (video_config.yuv_mode) |
| 167 | { |
| 168 | case VIDEO_YUV_MODE_NONE: |
| 169 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, |
| 170 | tempwidth, tempheight); |
| 171 | SDL_SetTextureScaleMode(sdl->texture_id, SDL_TEXTURESCALEMODE_NONE); |
| 172 | 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)); |
| 176 | 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); |
| 179 | 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)); |
| 183 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, |
| 184 | sdl->yuv_ovl_width * 2, sdl->yuv_ovl_height * 2); |
| 185 | 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)); |
| 189 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, |
| 190 | sdl->yuv_ovl_width, sdl->yuv_ovl_height); |
| 191 | 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)); |
| 195 | sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, |
| 196 | sdl->yuv_ovl_width * 2, sdl->yuv_ovl_height); |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | #endif |
| 118 | 201 | |
| 202 | //============================================================ |
| 203 | // yuv_overlay_init |
| 204 | //============================================================ |
| 205 | |
| 206 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 207 | static void yuv_overlay_init(sdl_window_info *window) |
| 208 | { |
| 209 | sdl_info *sdl = window->dxdata; |
| 210 | int minimum_width, minimum_height; |
| 211 | |
| 212 | render_target_get_minimum_size(window->target, &minimum_width, &minimum_height); |
| 213 | if (sdl->yuvsurf != NULL) |
| 214 | SDL_FreeYUVOverlay(sdl->yuvsurf); |
| 215 | if (sdl->yuv_bitmap != NULL) |
| 216 | { |
| 217 | free(sdl->yuv_bitmap); |
| 218 | } |
| 219 | sdl->yuv_bitmap = malloc_or_die(minimum_width*minimum_height*sizeof(UINT16)); |
| 220 | |
| 221 | mame_printf_verbose("SDL: Creating YUV-Overlay ...\n"); |
| 222 | switch (video_config.yuv_mode) |
| 223 | { |
| 224 | case VIDEO_YUV_MODE_YV12: |
| 225 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 226 | SDL_YV12_OVERLAY, sdl->sdlsurf); |
| 227 | break; |
| 228 | case VIDEO_YUV_MODE_YV12X2: |
| 229 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height*2, |
| 230 | SDL_YV12_OVERLAY, sdl->sdlsurf); |
| 231 | break; |
| 232 | case VIDEO_YUV_MODE_YUY2: |
| 233 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 234 | SDL_YUY2_OVERLAY, sdl->sdlsurf); |
| 235 | break; |
| 236 | case VIDEO_YUV_MODE_YUY2X2: |
| 237 | sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height, |
| 238 | SDL_YUY2_OVERLAY, sdl->sdlsurf); |
| 239 | break; |
| 240 | } |
| 241 | if ( sdl->yuvsurf == NULL ) { |
| 242 | mame_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); |
| 243 | //return 1; |
| 244 | } |
| 245 | sdl->yuv_ovl_width = minimum_width; |
| 246 | sdl->yuv_ovl_height = minimum_height; |
| 247 | |
| 248 | if (!shown_video_info) |
| 249 | { |
| 250 | mame_printf_verbose("YUV Mode : %s\n", yuv_mode_names[video_config.yuv_mode]); |
| 251 | mame_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height); |
| 252 | mame_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software"); |
| 253 | shown_video_info = 1; |
| 254 | } |
| 255 | } |
| 256 | #endif |
| 257 | |
| 258 | //============================================================ |
| 259 | // drawsdl_window_create |
| 260 | //============================================================ |
| 261 | |
| 262 | static int drawsdl_window_create(sdl_window_info *window, int width, int height) |
| 263 | { |
| 264 | sdl_info *sdl = window->dxdata; |
| 265 | |
| 119 | 266 | // allocate memory for our structures |
| 120 | 267 | sdl = malloc(sizeof(*sdl)); |
| 121 | 268 | memset(sdl, 0, sizeof(*sdl)); |
| 269 | |
| 122 | 270 | window->dxdata = sdl; |
| 123 | | window->yuv_lookup = NULL; |
| 124 | | window->yuv_bitmap = NULL; |
| 125 | | window->initialized = 0; |
| 126 | | sdl->totalColors = window->totalColors; |
| 271 | |
| 272 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 273 | window->extra_flags = (window->fullscreen ? |
| 274 | 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; |
| 127 | 281 | |
| 128 | | drawsdl_yuv_init(window); |
| 282 | SDL_SelectVideoDisplay(window->monitor->handle); |
| 283 | SDL_SetFullscreenDisplayMode(NULL); // Use desktop |
| 284 | window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 285 | width, height, window->extra_flags); |
| 286 | SDL_ShowWindow(window->window_id); |
| 287 | SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 288 | SDL_RaiseWindow(window->window_id); |
| 289 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 290 | |
| 291 | // create a texture |
| 292 | SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD); |
| 293 | SDL_SelectRenderer(window->window_id); |
| 294 | setup_texture(window, width, height); |
| 295 | #else |
| 296 | window->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 297 | // 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; |
| 300 | |
| 301 | sdl->sdlsurf = SDL_SetVideoMode(width, height, |
| 302 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 303 | |
| 304 | if (!sdl->sdlsurf) |
| 305 | return 1; |
| 306 | |
| 307 | window->width = sdl->sdlsurf->w; |
| 308 | window->height = sdl->sdlsurf->h; |
| 309 | |
| 310 | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 311 | { |
| 312 | yuv_overlay_init(window); |
| 313 | } |
| 314 | |
| 315 | // set the window title |
| 316 | SDL_WM_SetCaption(window->title, "SDLMAME"); |
| 317 | #endif |
| 318 | sdl->yuv_lookup = NULL; |
| 319 | sdl->blittimer = 0; |
| 320 | |
| 321 | drawsdl_yuv_init(sdl); |
| 129 | 322 | return 0; |
| 130 | 323 | } |
| 131 | 324 | |
| 132 | 325 | //============================================================ |
| 326 | // drawsdl_window_resize |
| 327 | //============================================================ |
| 328 | |
| 329 | static void drawsdl_window_resize(sdl_window_info *window, int width, int height) |
| 330 | { |
| 331 | sdl_info *sdl = window->dxdata; |
| 332 | |
| 333 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 334 | SDL_SetWindowSize(window->window_id, width, height); |
| 335 | SDL_GetWindowSize(window->window_id, &window->width, &window->height); |
| 336 | |
| 337 | // create a texture |
| 338 | SDL_SelectRenderer(window->window_id); |
| 339 | SDL_DestroyTexture(sdl->texture_id); |
| 340 | |
| 341 | setup_texture(window, window->width, window->height); |
| 342 | #else |
| 343 | SDL_FreeSurface(sdl->sdlsurf); |
| 344 | //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height); |
| 345 | |
| 346 | sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 347 | SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags); |
| 348 | window->width = sdl->sdlsurf->w; |
| 349 | window->height = sdl->sdlsurf->h; |
| 350 | |
| 351 | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 352 | { |
| 353 | yuv_overlay_init(window); |
| 354 | } |
| 355 | |
| 356 | #endif |
| 357 | } |
| 358 | |
| 359 | |
| 360 | //============================================================ |
| 133 | 361 | // drawsdl_window_destroy |
| 134 | 362 | //============================================================ |
| 135 | 363 | |
| r2959 | r2960 | |
| 141 | 369 | if (sdl == NULL) |
| 142 | 370 | return; |
| 143 | 371 | |
| 372 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 373 | SDL_SelectRenderer(window->window_id); |
| 374 | SDL_DestroyTexture(sdl->texture_id); |
| 375 | //SDL_DestroyRenderer(window->window_id); |
| 376 | SDL_DestroyWindow(window->window_id); |
| 377 | #else |
| 378 | if (sdl->sdlsurf) |
| 379 | { |
| 380 | SDL_FreeSurface(sdl->sdlsurf); |
| 381 | sdl->sdlsurf = NULL; |
| 382 | } |
| 383 | #endif |
| 144 | 384 | // free the memory in the window |
| 145 | 385 | |
| 146 | | free(sdl); |
| 147 | | window->dxdata = NULL; |
| 148 | | if (window->yuv_lookup != NULL) |
| 386 | if (sdl->yuv_lookup != NULL) |
| 149 | 387 | { |
| 150 | | free(window->yuv_lookup); |
| 151 | | window->yuv_lookup = NULL; |
| 388 | free(sdl->yuv_lookup); |
| 389 | sdl->yuv_lookup = NULL; |
| 152 | 390 | } |
| 153 | | if (window->yuv_bitmap != NULL) |
| 391 | if (sdl->yuv_bitmap != NULL) |
| 154 | 392 | { |
| 155 | | free(window->yuv_bitmap); |
| 156 | | window->yuv_bitmap = NULL; |
| 393 | free(sdl->yuv_bitmap); |
| 394 | sdl->yuv_bitmap = NULL; |
| 157 | 395 | } |
| 396 | window->dxdata = NULL; |
| 397 | free(sdl); |
| 158 | 398 | } |
| 159 | 399 | |
| 160 | 400 | //============================================================ |
| 401 | // drawsdl_window_clear |
| 402 | //============================================================ |
| 403 | |
| 404 | static void drawsdl_window_clear(sdl_window_info *window) |
| 405 | { |
| 406 | sdl_info *sdl = window->dxdata; |
| 407 | |
| 408 | sdl->blittimer = 3; |
| 409 | } |
| 410 | |
| 411 | //============================================================ |
| 161 | 412 | // drawsdl_window_get_primitives |
| 162 | 413 | //============================================================ |
| 163 | 414 | |
| 164 | 415 | static const render_primitive_list *drawsdl_window_get_primitives(sdl_window_info *window) |
| 165 | 416 | { |
| 166 | 417 | sdl_info *sdl = window->dxdata; |
| 167 | | if ((video_config.windowed) || (video_config.switchres)) |
| 418 | if ((!window->fullscreen) || (video_config.switchres)) |
| 168 | 419 | { |
| 169 | | sdlwindow_blit_surface_size(window, window->sdlsurf->w, window->sdlsurf->h); |
| 420 | sdlwindow_blit_surface_size(window, window->width, window->height); |
| 170 | 421 | } |
| 171 | 422 | else |
| 172 | 423 | { |
| 173 | 424 | sdlwindow_blit_surface_size(window, window->monitor->center_width, window->monitor->center_height); |
| 174 | 425 | } |
| 175 | 426 | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 176 | | render_target_set_bounds(window->target, sdl->blitwidth, sdl->blitheight, sdlvideo_monitor_get_aspect(window->monitor)); |
| 427 | render_target_set_bounds(window->target, window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor)); |
| 177 | 428 | else |
| 178 | | render_target_set_bounds(window->target, window->yuv_ovl_width, window->yuv_ovl_height, 0); |
| 429 | render_target_set_bounds(window->target, sdl->yuv_ovl_width, sdl->yuv_ovl_height, 0); |
| 179 | 430 | return render_target_get_primitives(window->target); |
| 180 | 431 | } |
| 181 | 432 | |
| r2959 | r2960 | |
| 187 | 438 | { |
| 188 | 439 | sdl_info *sdl = window->dxdata; |
| 189 | 440 | UINT8 *surfptr; |
| 441 | INT32 pitch; |
| 442 | int bpp; |
| 443 | Uint32 rmask, gmask, bmask, amask; |
| 190 | 444 | INT32 vofs, hofs, blitwidth, blitheight, ch, cw; |
| 191 | | SDL_Rect r; |
| 192 | 445 | |
| 193 | 446 | if (video_config.novideo) |
| 194 | 447 | { |
| r2959 | r2960 | |
| 200 | 453 | return 1; |
| 201 | 454 | |
| 202 | 455 | // lock it if we need it |
| 203 | | if (SDL_MUSTLOCK(window->sdlsurf)) SDL_LockSurface(window->sdlsurf); |
| 456 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 457 | |
| 458 | pitch = sdl->sdlsurf->pitch; |
| 459 | bpp = sdl->sdlsurf->format->BytesPerPixel; |
| 460 | rmask = sdl->sdlsurf->format->Rmask; |
| 461 | gmask = sdl->sdlsurf->format->Gmask; |
| 462 | bmask = sdl->sdlsurf->format->Bmask; |
| 463 | amask = sdl->sdlsurf->format->Amask; |
| 464 | |
| 465 | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf); |
| 466 | // Clear if necessary |
| 467 | |
| 468 | if (sdl->blittimer > 0) |
| 469 | { |
| 470 | memset(sdl->sdlsurf->pixels, 0, window->height * sdl->sdlsurf->pitch); |
| 471 | sdl->blittimer--; |
| 472 | } |
| 473 | |
| 474 | |
| 204 | 475 | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 205 | 476 | { |
| 206 | | SDL_LockYUVOverlay(window->yuvsurf); |
| 207 | | surfptr = (UINT8 *) window->yuv_bitmap; |
| 477 | SDL_LockYUVOverlay(sdl->yuvsurf); |
| 478 | surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->yuv_bitmap; |
| 479 | pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->yuv_bitmap; |
| 208 | 480 | } |
| 209 | 481 | else |
| 210 | | surfptr = (UINT8 *)window->sdlsurf->pixels; |
| 482 | surfptr = (UINT8 *)sdl->sdlsurf->pixels; |
| 483 | #else |
| 484 | SDL_SelectRenderer(window->window_id); |
| 485 | { |
| 486 | Uint32 format; |
| 487 | int access, w, h; |
| 488 | |
| 489 | SDL_QueryTexture(sdl->texture_id, &format, &access, &w, &h); |
| 490 | SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask); |
| 491 | bpp = bpp / 8; /* convert to bytes per pixels */ |
| 492 | } |
| 493 | |
| 494 | SDL_LockTexture(sdl->texture_id, NULL, 1, (void **) &surfptr, &pitch); |
| 495 | // Clear if necessary |
| 496 | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 497 | if (sdl->blittimer > 0) |
| 498 | { |
| 499 | memset(surfptr, 0, window->height * pitch); |
| 500 | sdl->blittimer--; |
| 501 | } |
| 502 | |
| 503 | #endif |
| 211 | 504 | // get ready to center the image |
| 212 | 505 | vofs = hofs = 0; |
| 213 | | blitwidth = sdl->blitwidth; |
| 214 | | blitheight = sdl->blitheight; |
| 506 | blitwidth = window->blitwidth; |
| 507 | blitheight = window->blitheight; |
| 215 | 508 | |
| 216 | 509 | // figure out what coordinate system to use for centering - in window mode it's always the |
| 217 | 510 | // SDL surface size. in fullscreen the surface covers all monitors, so center according to |
| 218 | 511 | // the first one only |
| 219 | | if ((!video_config.windowed) && (!video_config.switchres)) |
| 512 | if ((window->fullscreen) && (!video_config.switchres)) |
| 220 | 513 | { |
| 221 | 514 | ch = window->monitor->center_height; |
| 222 | 515 | cw = window->monitor->center_width; |
| 223 | 516 | } |
| 224 | 517 | else |
| 225 | 518 | { |
| 226 | | ch = window->sdlsurf->h; |
| 227 | | cw = window->sdlsurf->w; |
| 519 | ch = window->height; |
| 520 | cw = window->width; |
| 228 | 521 | } |
| 229 | 522 | |
| 230 | 523 | // do not crash if the window's smaller than the blit area |
| r2959 | r2960 | |
| 234 | 527 | } |
| 235 | 528 | else if (video_config.centerv) |
| 236 | 529 | { |
| 237 | | vofs = (ch - sdl->blitheight) / 2; |
| 530 | vofs = (ch - window->blitheight) / 2; |
| 238 | 531 | } |
| 239 | 532 | |
| 240 | 533 | if (blitwidth > cw) |
| r2959 | r2960 | |
| 243 | 536 | } |
| 244 | 537 | else if (video_config.centerh) |
| 245 | 538 | { |
| 246 | | hofs = (cw - sdl->blitwidth) / 2; |
| 539 | hofs = (cw - window->blitwidth) / 2; |
| 247 | 540 | } |
| 248 | 541 | |
| 249 | 542 | osd_lock_acquire(window->primlist->lock); |
| r2959 | r2960 | |
| 251 | 544 | // render to it |
| 252 | 545 | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 253 | 546 | { |
| 254 | | surfptr += ((vofs * window->sdlsurf->pitch) + (hofs * window->sdlsurf->format->BytesPerPixel)); |
| 255 | | switch (window->sdlsurf->format->Rmask) |
| 547 | surfptr += ((vofs * pitch) + (hofs * bpp)); |
| 548 | switch (rmask) |
| 256 | 549 | { |
| 257 | 550 | case 0x00ff0000: |
| 258 | | drawsdl_rgb888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 4); |
| 551 | drawsdl_rgb888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 4); |
| 259 | 552 | break; |
| 260 | 553 | |
| 261 | 554 | case 0x000000ff: |
| 262 | | drawsdl_bgr888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 4); |
| 555 | drawsdl_bgr888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 4); |
| 263 | 556 | break; |
| 264 | 557 | |
| 265 | 558 | case 0xf800: |
| 266 | | drawsdl_rgb565_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 2); |
| 559 | drawsdl_rgb565_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 2); |
| 267 | 560 | break; |
| 268 | 561 | |
| 269 | 562 | case 0x7c00: |
| 270 | | drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 2); |
| 563 | drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 2); |
| 271 | 564 | break; |
| 272 | 565 | |
| 273 | 566 | default: |
| 274 | | mame_printf_error("SDL: ERROR! Unknown video mode: R=%08X G=%08X B=%08X\n", window->sdlsurf->format->Rmask, window->sdlsurf->format->Gmask, window->sdlsurf->format->Bmask); |
| 567 | mame_printf_error("SDL: ERROR! Unknown video mode: R=%08X G=%08X B=%08X\n", rmask, gmask, bmask); |
| 275 | 568 | break; |
| 276 | 569 | } |
| 277 | 570 | } |
| 278 | 571 | else |
| 279 | 572 | { |
| 280 | | drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, window->yuv_ovl_width, window->yuv_ovl_height, window->yuv_ovl_width); |
| 573 | assert (sdl->yuv_bitmap != NULL); |
| 574 | 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); |
| 281 | 576 | switch (video_config.yuv_mode) |
| 282 | 577 | { |
| 283 | 578 | case VIDEO_YUV_MODE_YV12: |
| 284 | | yuv_RGB_to_YV12((UINT16 *)surfptr, window->yuv_ovl_width, window); |
| 579 | yuv_RGB_to_YV12((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 285 | 580 | break; |
| 286 | 581 | case VIDEO_YUV_MODE_YV12X2: |
| 287 | | yuv_RGB_to_YV12X2((UINT16 *)surfptr, window->yuv_ovl_width, window); |
| 582 | yuv_RGB_to_YV12X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 288 | 583 | break; |
| 289 | 584 | case VIDEO_YUV_MODE_YUY2: |
| 290 | | yuv_RGB_to_YUY2((UINT16 *)surfptr, window->yuv_ovl_width, window); |
| 585 | yuv_RGB_to_YUY2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 291 | 586 | break; |
| 292 | 587 | case VIDEO_YUV_MODE_YUY2X2: |
| 293 | | yuv_RGB_to_YUY2X2((UINT16 *)surfptr, window->yuv_ovl_width, window); |
| 588 | yuv_RGB_to_YUY2X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch); |
| 294 | 589 | break; |
| 295 | 590 | } |
| 296 | 591 | } |
| 592 | |
| 297 | 593 | osd_lock_release(window->primlist->lock); |
| 298 | 594 | |
| 299 | 595 | // unlock and flip |
| 300 | | if (SDL_MUSTLOCK(window->sdlsurf)) SDL_UnlockSurface(window->sdlsurf); |
| 596 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 597 | if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf); |
| 598 | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 599 | { |
| 600 | SDL_Flip(sdl->sdlsurf); |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | SDL_Rect r; |
| 301 | 605 | |
| 606 | SDL_UnlockYUVOverlay(sdl->yuvsurf); |
| 607 | r.x=hofs; |
| 608 | r.y=vofs; |
| 609 | r.w=blitwidth; |
| 610 | r.h=blitheight; |
| 611 | SDL_DisplayYUVOverlay(sdl->yuvsurf, &r); |
| 612 | } |
| 613 | #else |
| 614 | SDL_UnlockTexture(sdl->texture_id); |
| 302 | 615 | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 303 | | SDL_Flip(window->sdlsurf); |
| 616 | { |
| 617 | //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); |
| 618 | SDL_RenderCopy(sdl->texture_id, NULL, NULL); |
| 619 | SDL_RenderPresent(); |
| 620 | } |
| 304 | 621 | else |
| 305 | 622 | { |
| 306 | | SDL_UnlockYUVOverlay(window->yuvsurf); |
| 623 | SDL_Rect r; |
| 307 | 624 | r.x=hofs; |
| 308 | 625 | r.y=vofs; |
| 309 | 626 | r.w=blitwidth; |
| 310 | 627 | r.h=blitheight; |
| 311 | | SDL_DisplayYUVOverlay(window->yuvsurf, &r); |
| 628 | //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch); |
| 629 | SDL_RenderCopy(sdl->texture_id, NULL, &r); |
| 630 | SDL_RenderPresent(); |
| 312 | 631 | } |
| 632 | #endif |
| 313 | 633 | return 0; |
| 314 | 634 | } |
| 315 | 635 | |
| 316 | | |
| 317 | 636 | //============================================================ |
| 318 | 637 | // SOFTWARE RENDERING |
| 319 | 638 | //============================================================ |
| r2959 | r2960 | |
| 403 | 722 | #define YMASK (Y1MASK|Y2MASK) |
| 404 | 723 | #define UVMASK (UMASK|VMASK) |
| 405 | 724 | |
| 406 | | static void yuv_lookup_set(sdl_window_info *window, unsigned int pen, unsigned char red, |
| 725 | static void yuv_lookup_set(sdl_info *sdl, unsigned int pen, unsigned char red, |
| 407 | 726 | unsigned char green, unsigned char blue) |
| 408 | 727 | { |
| 409 | 728 | UINT32 y,u,v; |
| r2959 | r2960 | |
| 412 | 731 | |
| 413 | 732 | /* Storing this data in YUYV order simplifies using the data for |
| 414 | 733 | YUY2, both with and without smoothing... */ |
| 415 | | window->yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); |
| 734 | sdl->yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); |
| 416 | 735 | } |
| 417 | 736 | |
| 418 | | static void drawsdl_yuv_init(sdl_window_info *window) |
| 737 | static void drawsdl_yuv_init(sdl_info *sdl) |
| 419 | 738 | { |
| 420 | 739 | unsigned char r,g,b; |
| 421 | | if (window->yuv_lookup == NULL) |
| 422 | | window->yuv_lookup = malloc_or_die(65536*sizeof(UINT32)); |
| 740 | if (sdl->yuv_lookup == NULL) |
| 741 | sdl->yuv_lookup = malloc_or_die(65536*sizeof(UINT32)); |
| 423 | 742 | for (r = 0; r < 32; r++) |
| 424 | 743 | for (g = 0; g < 32; g++) |
| 425 | 744 | for (b = 0; b < 32; b++) |
| 426 | 745 | { |
| 427 | 746 | int idx = (r << 10) | (g << 5) | b; |
| 428 | | yuv_lookup_set(window, idx, |
| 747 | yuv_lookup_set(sdl, idx, |
| 429 | 748 | (r << 3) | (r >> 2), |
| 430 | 749 | (g << 3) | (g >> 2), |
| 431 | 750 | (b << 3) | (b >> 2)); |
| 432 | 751 | } |
| 433 | 752 | } |
| 434 | 753 | |
| 435 | | static void yuv_RGB_to_YV12(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 754 | static void yuv_RGB_to_YV12(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch) |
| 436 | 755 | { |
| 437 | 756 | int x, y; |
| 438 | 757 | UINT8 *dest_y; |
| r2959 | r2960 | |
| 440 | 759 | UINT8 *dest_v; |
| 441 | 760 | UINT16 *src; |
| 442 | 761 | UINT16 *src2; |
| 443 | | UINT32 *lookup = window->yuv_lookup; |
| 444 | | int yuv_pitch = window->yuvsurf->pitches[0]; |
| 762 | UINT32 *lookup = sdl->yuv_lookup; |
| 763 | UINT8 *pixels[3]; |
| 445 | 764 | int u1,v1,y1,u2,v2,y2,u3,v3,y3,u4,v4,y4; /* 12 */ |
| 446 | | |
| 447 | | for(y=0;y<window->yuv_ovl_height;y+=2) |
| 765 | |
| 766 | pixels[0] = ptr; |
| 767 | pixels[1] = ptr + pitch * sdl->yuv_ovl_height; |
| 768 | pixels[2] = pixels[1] + pitch * sdl->yuv_ovl_height / 4; |
| 769 | |
| 770 | for(y=0;y<sdl->yuv_ovl_height;y+=2) |
| 448 | 771 | { |
| 449 | | src=bitmap + (y * bw) ; |
| 450 | | src2=src + bw; |
| 772 | src=bitmap + (y * sdl->yuv_ovl_width) ; |
| 773 | src2=src + sdl->yuv_ovl_width; |
| 451 | 774 | |
| 452 | | dest_y = window->yuvsurf->pixels[0] + y * window->yuvsurf->pitches[0]; |
| 453 | | dest_v = window->yuvsurf->pixels[1] + (y>>1) * window->yuvsurf->pitches[1]; |
| 454 | | dest_u = window->yuvsurf->pixels[2] + (y>>1) * window->yuvsurf->pitches[2]; |
| 775 | dest_y = pixels[0] + y * pitch; |
| 776 | dest_v = pixels[1] + (y>>1) * pitch / 2; |
| 777 | dest_u = pixels[2] + (y>>1) * pitch / 2; |
| 455 | 778 | |
| 456 | | for(x=0;x<window->yuv_ovl_width;x+=2) |
| 779 | for(x=0;x<sdl->yuv_ovl_width;x+=2) |
| 457 | 780 | { |
| 458 | 781 | v1 = lookup[src[x]]; |
| 459 | 782 | y1 = (v1>>Y1SHIFT) & 0xff; |
| r2959 | r2960 | |
| 476 | 799 | v4 = (v4>>VSHIFT) & 0xff; |
| 477 | 800 | |
| 478 | 801 | dest_y[x] = y1; |
| 479 | | dest_y[x+yuv_pitch] = y3; |
| 802 | dest_y[x+pitch] = y3; |
| 480 | 803 | dest_y[x+1] = y2; |
| 481 | | dest_y[x+yuv_pitch+1] = y4; |
| 804 | dest_y[x+pitch+1] = y4; |
| 482 | 805 | |
| 483 | 806 | dest_u[x>>1] = (u1+u2+u3+u4)/4; |
| 484 | 807 | dest_v[x>>1] = (v1+v2+v3+v4)/4; |
| r2959 | r2960 | |
| 487 | 810 | } |
| 488 | 811 | } |
| 489 | 812 | |
| 490 | | static void yuv_RGB_to_YV12X2(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 813 | static void yuv_RGB_to_YV12X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch) |
| 491 | 814 | { |
| 492 | 815 | /* this one is used when scale==2 */ |
| 493 | 816 | unsigned int x,y; |
| r2959 | r2960 | |
| 495 | 818 | UINT8 *dest_u; |
| 496 | 819 | UINT8 *dest_v; |
| 497 | 820 | UINT16 *src; |
| 498 | | int yuv_pitch = window->yuvsurf->pitches[0]; |
| 499 | 821 | int u1,v1,y1; |
| 822 | UINT8 *pixels[3]; |
| 500 | 823 | |
| 501 | | for(y=0;y<window->yuv_ovl_height;y++) |
| 824 | pixels[0] = ptr; |
| 825 | pixels[1] = ptr + pitch * sdl->yuv_ovl_height * 2; |
| 826 | pixels[2] = pixels[1] + pitch * sdl->yuv_ovl_height / 2; |
| 827 | |
| 828 | for(y=0;y<sdl->yuv_ovl_height;y++) |
| 502 | 829 | { |
| 503 | | src=bitmap + (y * bw) ; |
| 830 | src = bitmap + (y * sdl->yuv_ovl_width) ; |
| 504 | 831 | |
| 505 | | dest_y = (UINT16 *)(window->yuvsurf->pixels[0] + 2*y * window->yuvsurf->pitches[0]); |
| 506 | | dest_v = window->yuvsurf->pixels[1] + y * window->yuvsurf->pitches[1]; |
| 507 | | dest_u = window->yuvsurf->pixels[2] + y * window->yuvsurf->pitches[2]; |
| 508 | | for(x=0;x<window->yuv_ovl_width;x++) |
| 832 | dest_y = (UINT16 *)(pixels[0] + 2 * y * pitch); |
| 833 | dest_v = pixels[1] + y * pitch / 2; |
| 834 | dest_u = pixels[2] + y * pitch / 2; |
| 835 | for(x=0;x<sdl->yuv_ovl_width;x++) |
| 509 | 836 | { |
| 510 | | v1 = window->yuv_lookup[src[x]]; |
| 511 | | y1 = (v1>>Y1SHIFT) & 0xff; |
| 512 | | u1 = (v1>>USHIFT) & 0xff; |
| 513 | | v1 = (v1>>VSHIFT) & 0xff; |
| 837 | v1 = sdl->yuv_lookup[src[x]]; |
| 838 | y1 = (v1 >> Y1SHIFT) & 0xff; |
| 839 | u1 = (v1 >> USHIFT) & 0xff; |
| 840 | v1 = (v1 >> VSHIFT) & 0xff; |
| 514 | 841 | |
| 515 | | dest_y[x+yuv_pitch/2]=y1<<8|y1; |
| 516 | | dest_y[x]=y1<<8|y1; |
| 842 | dest_y[x + pitch/2] = y1 << 8 | y1; |
| 843 | dest_y[x] = y1 << 8 | y1; |
| 517 | 844 | dest_u[x] = u1; |
| 518 | 845 | dest_v[x] = v1; |
| 519 | 846 | } |
| 520 | 847 | } |
| 521 | 848 | } |
| 522 | 849 | |
| 523 | | static void yuv_RGB_to_YUY2(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 850 | static void yuv_RGB_to_YUY2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch) |
| 524 | 851 | { |
| 525 | 852 | /* this one is used when scale==2 */ |
| 526 | 853 | unsigned int y; |
| r2959 | r2960 | |
| 528 | 855 | UINT16 *src; |
| 529 | 856 | UINT16 *end; |
| 530 | 857 | UINT32 p1,p2,uv; |
| 531 | | UINT32 *lookup = window->yuv_lookup; |
| 532 | | int yuv_pitch = window->yuvsurf->pitches[0]/4; |
| 858 | UINT32 *lookup = sdl->yuv_lookup; |
| 859 | int yuv_pitch = pitch/4; |
| 533 | 860 | |
| 534 | | for(y=0;y<window->yuv_ovl_height;y++) |
| 861 | for(y=0;y<sdl->yuv_ovl_height;y++) |
| 535 | 862 | { |
| 536 | | src=bitmap + (y * bw) ; |
| 537 | | end=src+window->yuv_ovl_width; |
| 863 | src=bitmap + (y * sdl->yuv_ovl_width) ; |
| 864 | end=src+sdl->yuv_ovl_width; |
| 538 | 865 | |
| 539 | | dest = (UINT32 *) window->yuvsurf->pixels[0]; |
| 866 | dest = (UINT32 *) ptr; |
| 540 | 867 | dest += y * yuv_pitch; |
| 541 | 868 | for(; src<end; src+=2) |
| 542 | 869 | { |
| r2959 | r2960 | |
| 549 | 876 | } |
| 550 | 877 | } |
| 551 | 878 | |
| 552 | | static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 879 | static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch) |
| 553 | 880 | { |
| 554 | 881 | /* this one is used when scale==2 */ |
| 555 | 882 | unsigned int y; |
| 556 | 883 | UINT32 *dest; |
| 557 | 884 | UINT16 *src; |
| 558 | 885 | UINT16 *end; |
| 559 | | UINT32 *lookup = window->yuv_lookup; |
| 560 | | int yuv_pitch = window->yuvsurf->pitches[0]/4; |
| 886 | UINT32 *lookup = sdl->yuv_lookup; |
| 887 | int yuv_pitch = pitch / 4; |
| 561 | 888 | |
| 562 | | for(y=0;y<window->yuv_ovl_height;y++) |
| 889 | for(y=0;y<sdl->yuv_ovl_height;y++) |
| 563 | 890 | { |
| 564 | | src=bitmap + (y * bw) ; |
| 565 | | end=src+window->yuv_ovl_width; |
| 891 | src=bitmap + (y * sdl->yuv_ovl_width) ; |
| 892 | end=src+sdl->yuv_ovl_width; |
| 566 | 893 | |
| 567 | | dest = (UINT32 *) window->yuvsurf->pixels[0]; |
| 894 | dest = (UINT32 *) ptr; |
| 568 | 895 | dest += (y * yuv_pitch); |
| 569 | 896 | for(; src<end; src++) |
| 570 | 897 | { |
src/osd/sdl/video.c
| r2959 | r2960 | |
| 54 | 54 | |
| 55 | 55 | #include "osd_opengl.h" |
| 56 | 56 | |
| 57 | #include "uiinput.h" |
| 58 | |
| 57 | 59 | #ifdef MESS |
| 58 | 60 | #include "menu.h" |
| 59 | 61 | #endif |
| r2959 | r2960 | |
| 186 | 188 | #if defined(SDLMAME_WIN32) // Win32 version |
| 187 | 189 | MONITORINFOEX info; |
| 188 | 190 | info.cbSize = sizeof(info); |
| 189 | | GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info); |
| 191 | GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info); |
| 190 | 192 | monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left; |
| 191 | 193 | monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; |
| 192 | 194 | strcpy(monitor->monitor_device, info.szDevice); |
| 195 | #elif (SDL_VERSION_ATLEAST(1,3,0)) |
| 196 | SDL_DisplayMode dmode; |
| 197 | |
| 198 | SDL_SelectVideoDisplay(monitor->handle); |
| 199 | SDL_GetDesktopDisplayMode(&dmode); |
| 200 | monitor->monitor_width = dmode.w; |
| 201 | monitor->monitor_height = dmode.h; |
| 202 | monitor->center_width = dmode.w; |
| 203 | monitor->center_height = dmode.h; |
| 193 | 204 | #elif defined(SDLMAME_MACOSX) // Mac OS X Core Imaging version |
| 194 | 205 | CGDirectDisplayID primary; |
| 195 | 206 | CGRect dbounds; |
| r2959 | r2960 | |
| 204 | 215 | #elif defined(SDLMAME_X11) || defined(SDLMAME_NO_X11) // X11 version |
| 205 | 216 | { |
| 206 | 217 | #if defined(SDLMAME_X11) |
| 207 | | //FIXME: The code below fails for SDL1.3 |
| 208 | | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 209 | 218 | // X11 version |
| 210 | 219 | int screen; |
| 211 | 220 | SDL_SysWMinfo info; |
| r2959 | r2960 | |
| 237 | 246 | } |
| 238 | 247 | } |
| 239 | 248 | else |
| 240 | | #endif |
| 241 | | #endif |
| 249 | #endif // defined(SDLMAME_X11) |
| 242 | 250 | { |
| 243 | 251 | static int first_call=0; |
| 244 | 252 | static int cw, ch; |
| r2959 | r2960 | |
| 251 | 259 | |
| 252 | 260 | sdl_vi = SDL_GetVideoInfo(); |
| 253 | 261 | #if (SDL_VERSION_ATLEAST(1,2,10)) |
| 254 | | //FIXME: File a bug for SDL 1.3 |
| 255 | | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 256 | | cw = 0; |
| 257 | | ch = 0; |
| 258 | | #else |
| 259 | 262 | cw = sdl_vi->current_w; |
| 260 | 263 | ch = sdl_vi->current_h; |
| 261 | 264 | #endif |
| 262 | | #endif |
| 263 | 265 | first_call=1; |
| 264 | 266 | if ((cw==0) || (ch==0)) |
| 265 | 267 | { |
| r2959 | r2960 | |
| 293 | 295 | #endif |
| 294 | 296 | |
| 295 | 297 | { |
| 298 | //FIXME: Code not really suitable for multiple monitors |
| 296 | 299 | static int info_shown=0; |
| 297 | 300 | if (!info_shown) |
| 298 | 301 | { |
| r2959 | r2960 | |
| 350 | 353 | { |
| 351 | 354 | profiler_mark(PROFILER_BLIT); |
| 352 | 355 | for (window = sdl_window_list; window != NULL; window = window->next) |
| 353 | | sdlwindow_video_window_update(window); |
| 356 | sdlwindow_video_window_update(machine, window); |
| 354 | 357 | profiler_mark(PROFILER_END); |
| 355 | 358 | } |
| 356 | 359 | |
| r2959 | r2960 | |
| 365 | 368 | //============================================================ |
| 366 | 369 | // add_primary_monitor |
| 367 | 370 | //============================================================ |
| 368 | | #ifndef SDLMAME_WIN32 |
| 371 | #if !defined(SDLMAME_WIN32) && !(SDL_VERSION_ATLEAST(1,3,0)) |
| 369 | 372 | static void add_primary_monitor(void *data) |
| 370 | 373 | { |
| 371 | 374 | sdl_monitor_info ***tailptr = (sdl_monitor_info ***)data; |
| r2959 | r2960 | |
| 448 | 451 | |
| 449 | 452 | #ifdef SDLMAME_WIN32 |
| 450 | 453 | EnumDisplayMonitors(NULL, NULL, monitor_enum_callback, (LPARAM)&tailptr); |
| 454 | #elif (SDL_VERSION_ATLEAST(1,3,0)) |
| 455 | { |
| 456 | int i; |
| 457 | |
| 458 | for (i = 0; i < SDL_GetNumVideoDisplays(); i++) |
| 459 | { |
| 460 | sdl_monitor_info *monitor; |
| 461 | SDL_DisplayMode dmode; |
| 462 | |
| 463 | // allocate a new monitor info |
| 464 | monitor = malloc_or_die(sizeof(*monitor)); |
| 465 | memset(monitor, 0, sizeof(*monitor)); |
| 466 | |
| 467 | snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", SDLOPTION_SCREEN(""),i); |
| 468 | |
| 469 | SDL_GetDesktopDisplayMode(&dmode); |
| 470 | monitor->monitor_width = dmode.w; |
| 471 | monitor->monitor_height = dmode.h; |
| 472 | monitor->center_width = dmode.w; |
| 473 | monitor->center_height = dmode.h; |
| 474 | monitor->handle = i; |
| 475 | // guess the aspect ratio assuming square pixels |
| 476 | monitor->aspect = (float)(dmode.w) / (float)(dmode.h); |
| 477 | mame_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->monitor_device, dmode.w, dmode.h); |
| 478 | |
| 479 | // save the primary monitor handle |
| 480 | if (i == 0) |
| 481 | primary_monitor = monitor; |
| 482 | |
| 483 | // hook us into the list |
| 484 | *tailptr = monitor; |
| 485 | tailptr = &monitor->next; |
| 486 | } |
| 487 | } |
| 451 | 488 | #else |
| 452 | 489 | add_primary_monitor((void *)&tailptr); |
| 453 | 490 | #endif |
| r2959 | r2960 | |
| 457 | 494 | // pick_monitor |
| 458 | 495 | //============================================================ |
| 459 | 496 | |
| 497 | #if (SDL_VERSION_ATLEAST(1,3,0)) || defined(SDLMAME_WIN32) |
| 460 | 498 | static sdl_monitor_info *pick_monitor(int index) |
| 461 | 499 | { |
| 462 | 500 | sdl_monitor_info *monitor; |
| 463 | | #if SDL_MULTIMON || defined(SDLMAME_WIN32) |
| 464 | 501 | const char *scrname; |
| 465 | 502 | int moncount = 0; |
| 466 | | #endif |
| 467 | 503 | char option[20]; |
| 468 | 504 | float aspect; |
| 469 | 505 | |
| 470 | 506 | // get the screen option |
| 471 | | #if SDL_MULTIMON || defined(SDLMAME_WIN32) |
| 472 | 507 | sprintf(option, SDLOPTION_SCREEN("%d"), index); |
| 473 | 508 | scrname = options_get_string(mame_options(), option); |
| 474 | | #endif |
| 475 | 509 | |
| 476 | 510 | // get the aspect ratio |
| 477 | 511 | sprintf(option, SDLOPTION_ASPECT("%d"), index); |
| 478 | 512 | aspect = get_aspect(option, TRUE); |
| 479 | 513 | |
| 480 | 514 | // look for a match in the name first |
| 481 | | #if SDL_MULTIMON || defined(SDLMAME_WIN32) |
| 482 | 515 | if (scrname != NULL) |
| 483 | | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 484 | | { |
| 516 | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 517 | { |
| 485 | 518 | moncount++; |
| 486 | 519 | if (strcmp(scrname, monitor->monitor_device) == 0) |
| 487 | 520 | goto finishit; |
| r2959 | r2960 | |
| 489 | 522 | |
| 490 | 523 | // didn't find it; alternate monitors until we hit the jackpot |
| 491 | 524 | index %= moncount; |
| 492 | | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 525 | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 493 | 526 | if (index-- == 0) |
| 494 | 527 | goto finishit; |
| 495 | | #endif |
| 496 | 528 | |
| 497 | 529 | // return the primary just in case all else fails |
| 498 | 530 | monitor = primary_monitor; |
| 499 | 531 | |
| 500 | | #if SDL_MULTIMON || defined(SDLMAME_WIN32) |
| 501 | 532 | finishit: |
| 502 | | #endif |
| 503 | 533 | if (aspect != 0) |
| 504 | 534 | { |
| 505 | 535 | monitor->aspect = aspect; |
| 506 | 536 | } |
| 507 | 537 | return monitor; |
| 508 | 538 | } |
| 539 | #else |
| 540 | static sdl_monitor_info *pick_monitor(int index) |
| 541 | { |
| 542 | sdl_monitor_info *monitor; |
| 543 | char option[20]; |
| 544 | float aspect; |
| 509 | 545 | |
| 546 | // get the aspect ratio |
| 547 | sprintf(option, SDLOPTION_ASPECT("%d"), index); |
| 548 | aspect = get_aspect(option, TRUE); |
| 549 | |
| 550 | // return the primary just in case all else fails |
| 551 | monitor = primary_monitor; |
| 552 | |
| 553 | if (aspect != 0) |
| 554 | { |
| 555 | monitor->aspect = aspect; |
| 556 | } |
| 557 | return monitor; |
| 558 | } |
| 559 | #endif |
| 560 | |
| 510 | 561 | //============================================================ |
| 511 | 562 | // check_osd_inputs |
| 512 | 563 | //============================================================ |
| 513 | 564 | |
| 514 | 565 | static void check_osd_inputs(running_machine *machine) |
| 515 | 566 | { |
| 516 | | sdl_window_info *window = sdl_window_list; |
| 567 | sdl_window_info *window = sdlinput_get_focus_window(machine); |
| 517 | 568 | |
| 518 | 569 | // check for toggling fullscreen mode |
| 519 | | if (input_ui_pressed(machine, IPT_OSD_1)) |
| 520 | | sdlwindow_toggle_full_screen(window); |
| 570 | if (ui_input_pressed(machine, IPT_OSD_1)) |
| 571 | sdlwindow_toggle_full_screen(machine, window); |
| 521 | 572 | |
| 522 | | if (input_ui_pressed(machine, IPT_OSD_2)) |
| 573 | if (ui_input_pressed(machine, IPT_OSD_2)) |
| 523 | 574 | { |
| 524 | 575 | video_config.fullstretch = !video_config.fullstretch; |
| 525 | 576 | ui_popup_time(1, "Uneven stretch %s", video_config.fullstretch? "enabled":"disabled"); |
| 526 | 577 | } |
| 527 | 578 | |
| 528 | | if (input_ui_pressed(machine, IPT_OSD_4)) |
| 579 | if (ui_input_pressed(machine, IPT_OSD_4)) |
| 529 | 580 | { |
| 530 | 581 | video_config.keepaspect = !video_config.keepaspect; |
| 531 | 582 | ui_popup_time(1, "Keepaspect %s", video_config.keepaspect? "enabled":"disabled"); |
| 532 | 583 | } |
| 533 | 584 | |
| 534 | | #if USE_OPENGL |
| 535 | | if (input_ui_pressed(machine, IPT_OSD_5)) |
| 585 | if (USE_OPENGL) |
| 536 | 586 | { |
| 537 | | video_config.filter = !video_config.filter; |
| 538 | | ui_popup_time(1, "Filter %s", video_config.filter? "enabled":"disabled"); |
| 587 | if (ui_input_pressed(machine, IPT_OSD_5)) |
| 588 | { |
| 589 | video_config.filter = !video_config.filter; |
| 590 | ui_popup_time(1, "Filter %s", video_config.filter? "enabled":"disabled"); |
| 591 | } |
| 539 | 592 | } |
| 540 | | #endif |
| 541 | 593 | |
| 542 | | if (input_ui_pressed(machine, IPT_OSD_6)) |
| 543 | | sdlwindow_modify_prescale(window, -1); |
| 594 | if (ui_input_pressed(machine, IPT_OSD_6)) |
| 595 | sdlwindow_modify_prescale(machine, window, -1); |
| 544 | 596 | |
| 545 | | if (input_ui_pressed(machine, IPT_OSD_7)) |
| 546 | | sdlwindow_modify_prescale(window, 1); |
| 597 | if (ui_input_pressed(machine, IPT_OSD_7)) |
| 598 | sdlwindow_modify_prescale(machine, window, 1); |
| 547 | 599 | |
| 548 | | if (input_ui_pressed(machine, IPT_OSD_8)) |
| 549 | | sdlwindow_modify_effect(window, -1); |
| 600 | if (ui_input_pressed(machine, IPT_OSD_8)) |
| 601 | sdlwindow_modify_effect(machine, window, -1); |
| 550 | 602 | |
| 551 | | if (input_ui_pressed(machine, IPT_OSD_9)) |
| 552 | | sdlwindow_modify_effect(window, 1); |
| 603 | if (ui_input_pressed(machine, IPT_OSD_9)) |
| 604 | sdlwindow_modify_effect(machine, window, 1); |
| 553 | 605 | |
| 554 | | if (input_ui_pressed(machine, IPT_OSD_10)) |
| 555 | | sdlwindow_toggle_draw(window); |
| 606 | if (ui_input_pressed(machine, IPT_OSD_10)) |
| 607 | sdlwindow_toggle_draw(machine, window); |
| 556 | 608 | } |
| 557 | 609 | |
| 558 | 610 | |
| r2959 | r2960 | |
| 605 | 657 | if (options_get_int(mame_options(), OPTION_SECONDS_TO_RUN) == 0) |
| 606 | 658 | mame_printf_warning("Warning: -video none doesn't make much sense without -seconds_to_run\n"); |
| 607 | 659 | } |
| 608 | | #if USE_OPENGL |
| 609 | | else if (strcmp(stemp, SDLOPTVAL_OPENGL) == 0) |
| 660 | else if (USE_OPENGL && (strcmp(stemp, SDLOPTVAL_OPENGL) == 0)) |
| 610 | 661 | video_config.mode = VIDEO_MODE_OPENGL; |
| 611 | | else if (strcmp(stemp, SDLOPTVAL_OPENGL16) == 0) |
| 662 | else if (USE_OPENGL && (strcmp(stemp, SDLOPTVAL_OPENGL16) == 0)) |
| 612 | 663 | { |
| 613 | 664 | video_config.mode = VIDEO_MODE_OPENGL; |
| 614 | 665 | video_config.prefer16bpp_tex = 1; |
| 615 | 666 | } |
| 616 | | #endif |
| 617 | 667 | else |
| 618 | 668 | { |
| 619 | 669 | mame_printf_warning("Invalid video value %s; reverting to software\n", stemp); |
| r2959 | r2960 | |
| 717 | 767 | // misc options: sanity check values |
| 718 | 768 | |
| 719 | 769 | // global options: sanity check values |
| 770 | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 720 | 771 | if (video_config.numscreens < 1 || video_config.numscreens > 1) //MAX_VIDEO_WINDOWS) |
| 721 | 772 | { |
| 722 | 773 | mame_printf_warning("Invalid numscreens value %d; reverting to 1\n", video_config.numscreens); |
| 723 | 774 | video_config.numscreens = 1; |
| 724 | 775 | } |
| 725 | | |
| 776 | #else |
| 777 | if (video_config.numscreens < 1 || video_config.numscreens > MAX_VIDEO_WINDOWS) |
| 778 | { |
| 779 | mame_printf_warning("Invalid numscreens value %d; reverting to 1\n", video_config.numscreens); |
| 780 | video_config.numscreens = 1; |
| 781 | } |
| 782 | #endif |
| 726 | 783 | // yuv settings ... |
| 727 | 784 | stemp = options_get_string(mame_options(), SDLOPTION_YUVMODE); |
| 728 | 785 | if (strcmp(stemp, SDLOPTVAL_NONE) == 0) |
src/osd/sdl/window.c
| r2959 | r2960 | |
| 91 | 91 | //============================================================ |
| 92 | 92 | |
| 93 | 93 | static sdl_window_info **last_window_ptr; |
| 94 | | static int shown_video_info = 0; |
| 95 | 94 | |
| 96 | 95 | // event handling |
| 97 | 96 | static int multithreading_enabled; |
| 98 | 97 | static osd_work_queue *work_queue; |
| 99 | 98 | static int main_threadid; |
| 100 | 99 | static int window_threadid; |
| 101 | | static int dll_loaded; |
| 102 | 100 | |
| 103 | 101 | static const char *yuv_mode_names[] = { "none", "yv12", "yv12x2", "yuy2", "yuy2x2" }; |
| 104 | 102 | |
| r2959 | r2960 | |
| 111 | 109 | struct _worker_param { |
| 112 | 110 | sdl_window_info *window; |
| 113 | 111 | const render_primitive_list *list; |
| 112 | running_machine *machine; |
| 114 | 113 | int resize_new_width; |
| 115 | 114 | int resize_new_height; |
| 116 | | int times; |
| 117 | 115 | }; |
| 118 | 116 | |
| 119 | 117 | |
| r2959 | r2960 | |
| 127 | 125 | static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt ); |
| 128 | 126 | static OSDWORK_CALLBACK( sdlwindow_resize_wt ); |
| 129 | 127 | static OSDWORK_CALLBACK( sdlwindow_toggle_full_screen_wt ); |
| 130 | | static void sdlwindow_clear_surface(sdl_window_info *window, int times); |
| 131 | | static void sdlwindow_update_cursor_state(void); |
| 128 | static void sdlwindow_clear_surface(sdl_window_info *window); |
| 129 | static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window); |
| 132 | 130 | static void sdlwindow_sync(void); |
| 133 | 131 | |
| 134 | | |
| 135 | 132 | static void get_min_bounds(sdl_window_info *window, int *window_width, int *window_height, int constrain); |
| 136 | 133 | static void get_max_bounds(sdl_window_info *window, int *window_width, int *window_height, int constrain); |
| 137 | 134 | |
| r2959 | r2960 | |
| 146 | 143 | { |
| 147 | 144 | wp->window=NULL; |
| 148 | 145 | wp->list=NULL; |
| 146 | wp->machine=NULL; |
| 149 | 147 | wp->resize_new_width=0; |
| 150 | 148 | wp->resize_new_height=0; |
| 151 | | wp->times=0; |
| 152 | 149 | } |
| 153 | 150 | |
| 154 | 151 | //============================================================ |
| r2959 | r2960 | |
| 190 | 187 | { |
| 191 | 188 | window_threadid = SDL_ThreadID(); |
| 192 | 189 | |
| 193 | | #ifdef SDLMAME_WIN32 |
| 194 | | if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) { |
| 195 | | mame_printf_error("Could not initialize SDL: %s.\n", SDL_GetError()); |
| 196 | | exit(-1); |
| 190 | if (SDLMAME_INIT_IN_WORKER_THREAD) |
| 191 | { |
| 192 | if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) |
| 193 | { |
| 194 | mame_printf_error("Could not initialize SDL: %s.\n", SDL_GetError()); |
| 195 | exit(-1); |
| 196 | } |
| 197 | 197 | } |
| 198 | | #endif |
| 199 | 198 | return NULL; |
| 200 | 199 | } |
| 201 | 200 | |
| r2959 | r2960 | |
| 251 | 250 | |
| 252 | 251 | // set up the window list |
| 253 | 252 | last_window_ptr = &sdl_window_list; |
| 254 | | dll_loaded = 0; |
| 255 | 253 | return 0; |
| 256 | 254 | } |
| 257 | 255 | |
| r2959 | r2960 | |
| 274 | 272 | // (main thread) |
| 275 | 273 | //============================================================ |
| 276 | 274 | |
| 277 | | #ifdef SDLMAME_WIN32 |
| 278 | 275 | static OSDWORK_CALLBACK( sdlwindow_exit_wt ) |
| 279 | 276 | { |
| 280 | | SDL_Quit(); |
| 277 | if (SDLMAME_INIT_IN_WORKER_THREAD) |
| 278 | SDL_Quit(); |
| 279 | |
| 280 | free(param); |
| 281 | 281 | return NULL; |
| 282 | 282 | } |
| 283 | | #endif |
| 284 | 283 | |
| 285 | 284 | static void sdlwindow_exit(running_machine *machine) |
| 286 | 285 | { |
| r2959 | r2960 | |
| 303 | 302 | // kill the drawers |
| 304 | 303 | (*draw.exit)(); |
| 305 | 304 | |
| 306 | | #ifdef SDLMAME_WIN32 |
| 307 | 305 | execute_async_wait(&sdlwindow_exit_wt, NULL); |
| 308 | | #endif |
| 306 | |
| 309 | 307 | if (multithreading_enabled) |
| 310 | 308 | { |
| 311 | 309 | osd_work_queue_wait(work_queue, 100000); |
| r2959 | r2960 | |
| 327 | 325 | |
| 328 | 326 | void sdlwindow_blit_surface_size(sdl_window_info *window, int window_width, int window_height) |
| 329 | 327 | { |
| 330 | | sdl_info *sdl = window->dxdata; |
| 331 | 328 | INT32 newwidth, newheight; |
| 332 | | int xscale, yscale; |
| 329 | int xscale = 1, yscale = 1; |
| 333 | 330 | float desired_aspect = 1.0f; |
| 334 | 331 | INT32 target_width = window_width; |
| 335 | 332 | INT32 target_height = window_height; |
| r2959 | r2960 | |
| 346 | 343 | desired_aspect = (float)target_width / (float)target_height; |
| 347 | 344 | } |
| 348 | 345 | |
| 349 | | // logerror("Render target wants %d x %d, minimum is %d x %d\n", target_width, target_height, newwidth, newheight); |
| 350 | | |
| 351 | | // don't allow below 1:1 size - this prevents the OutRunners "death spiral" |
| 352 | | // that would occur if you kept rotating it with fullstretch on in SDLMAME u10 test 2. |
| 353 | | if ((target_width >= newwidth) && (target_height >= newheight)) |
| 354 | | { |
| 355 | | newwidth = target_width; |
| 356 | | newheight = target_height; |
| 357 | | } |
| 358 | | |
| 359 | 346 | // non-integer scaling - often gives more pleasing results in full screen |
| 360 | 347 | if (!video_config.fullstretch) |
| 361 | 348 | { |
| r2959 | r2960 | |
| 397 | 384 | newwidth *= xscale; |
| 398 | 385 | newheight *= yscale; |
| 399 | 386 | } |
| 387 | else |
| 388 | { |
| 389 | newwidth = target_width; |
| 390 | newheight = target_height; |
| 391 | } |
| 400 | 392 | |
| 401 | 393 | if ((render_target_get_layer_config(window->target) & LAYER_CONFIG_ZOOM_TO_SCREEN) |
| 402 | 394 | && video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 403 | 395 | newwidth = window_width; |
| 404 | 396 | |
| 405 | | if (((sdl->blitwidth != newwidth) || (sdl->blitheight != newheight)) && !(video_config.mode == VIDEO_MODE_OPENGL) && (window->sdlsurf)) |
| 406 | | { |
| 407 | | sdlwindow_clear_surface(window, 3); |
| 408 | | } |
| 409 | | |
| 410 | | sdl->blitwidth = newwidth; |
| 411 | | sdl->blitheight = newheight; |
| 397 | if ((window->blitwidth != newwidth) || (window->blitheight != newheight)) |
| 398 | sdlwindow_clear_surface(window); |
| 399 | |
| 400 | window->blitwidth = newwidth; |
| 401 | window->blitheight = newheight; |
| 412 | 402 | } |
| 413 | 403 | |
| 414 | | //============================================================ |
| 415 | | // yuv_overlay_init |
| 416 | | //============================================================ |
| 417 | 404 | |
| 418 | | static void yuv_overlay_init(sdl_window_info *window) |
| 419 | | { |
| 420 | | int minimum_width, minimum_height; |
| 421 | | |
| 422 | | render_target_get_minimum_size(window->target, &minimum_width, &minimum_height); |
| 423 | | if (window->yuvsurf != NULL) |
| 424 | | SDL_FreeYUVOverlay(window->yuvsurf); |
| 425 | | if (window->yuv_bitmap != NULL) |
| 426 | | { |
| 427 | | free(window->yuv_bitmap); |
| 428 | | } |
| 429 | | window->yuv_bitmap = malloc_or_die(minimum_width*minimum_height*sizeof(UINT16)); |
| 430 | | |
| 431 | | mame_printf_verbose("SDL: Creating YUV-Overlay ...\n"); |
| 432 | | switch (video_config.yuv_mode) |
| 433 | | { |
| 434 | | case VIDEO_YUV_MODE_YV12: |
| 435 | | window->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 436 | | SDL_YV12_OVERLAY, window->sdlsurf); |
| 437 | | break; |
| 438 | | case VIDEO_YUV_MODE_YV12X2: |
| 439 | | window->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height*2, |
| 440 | | SDL_YV12_OVERLAY, window->sdlsurf); |
| 441 | | break; |
| 442 | | case VIDEO_YUV_MODE_YUY2: |
| 443 | | window->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height, |
| 444 | | SDL_YUY2_OVERLAY, window->sdlsurf); |
| 445 | | break; |
| 446 | | case VIDEO_YUV_MODE_YUY2X2: |
| 447 | | window->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height, |
| 448 | | SDL_YUY2_OVERLAY, window->sdlsurf); |
| 449 | | break; |
| 450 | | } |
| 451 | | if ( window->yuvsurf == NULL ) { |
| 452 | | mame_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); |
| 453 | | //return 1; |
| 454 | | } |
| 455 | | window->yuv_ovl_width = minimum_width; |
| 456 | | window->yuv_ovl_height = minimum_height; |
| 457 | | |
| 458 | | if (!shown_video_info) |
| 459 | | { |
| 460 | | mame_printf_verbose("YUV Mode : %s\n", yuv_mode_names[video_config.yuv_mode]); |
| 461 | | mame_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height); |
| 462 | | mame_printf_verbose("YUV Acceleration : %s\n", window->yuvsurf->hw_overlay ? "Hardware" : "Software"); |
| 463 | | shown_video_info = 1; |
| 464 | | } |
| 465 | | } |
| 466 | | |
| 467 | 405 | //============================================================ |
| 468 | 406 | // sdlwindow_resize |
| 469 | 407 | // (main thread) |
| r2959 | r2960 | |
| 471 | 409 | |
| 472 | 410 | static OSDWORK_CALLBACK( sdlwindow_resize_wt ) |
| 473 | 411 | { |
| 474 | | sdl_window_info *window = sdl_window_list; |
| 475 | | worker_param *wp = (worker_param *) param; |
| 412 | worker_param * wp = (worker_param *) param; |
| 413 | sdl_window_info * window = wp->window; |
| 476 | 414 | |
| 477 | 415 | ASSERT_WINDOW_THREAD(); |
| 478 | 416 | |
| 479 | 417 | draw.window_destroy_all_textures(window); |
| 418 | draw.window_resize(window, wp->resize_new_width, wp->resize_new_height); |
| 480 | 419 | |
| 481 | | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 482 | | SDL_FreeSurface(window->sdlsurf); |
| 483 | | #endif |
| 484 | | //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height); |
| 485 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 486 | | window->sdlsurf = SDL_SetVideoMode(wp->resize_new_width, wp->resize_new_height, 0, SDL_SWSURFACE | |
| 487 | | SDL_DOUBLEBUF | SDL_ANYFORMAT | window->extra_flags); |
| 488 | | else |
| 489 | | { |
| 490 | | window->sdlsurf = SDL_SetVideoMode(wp->resize_new_width, wp->resize_new_height, 0, SDL_HWSURFACE | |
| 491 | | SDL_DOUBLEBUF | SDL_ANYFORMAT | window->extra_flags); |
| 492 | | yuv_overlay_init(window); |
| 493 | | } |
| 494 | | #if USE_OPENGL |
| 495 | | if (video_config.mode == VIDEO_MODE_OPENGL) |
| 496 | | drawogl_init_ogl_context(); |
| 497 | | #endif |
| 498 | 420 | sdlwindow_blit_surface_size(window, wp->resize_new_width, wp->resize_new_height); |
| 421 | |
| 422 | sdlwindow_clear_surface(window); |
| 423 | |
| 499 | 424 | free(wp); |
| 500 | 425 | return NULL; |
| 501 | 426 | } |
| r2959 | r2960 | |
| 506 | 431 | |
| 507 | 432 | ASSERT_MAIN_THREAD(); |
| 508 | 433 | |
| 509 | | if (width == window->sdlsurf->w && height == window->sdlsurf->h) |
| 434 | if (width == window->width && height == window->height) |
| 510 | 435 | return; |
| 511 | 436 | |
| 512 | 437 | clear_worker_param(&wp); |
| 513 | 438 | wp.resize_new_width = width; |
| 514 | 439 | wp.resize_new_height = height; |
| 440 | wp.window = window; |
| 515 | 441 | |
| 516 | 442 | execute_async_wait(&sdlwindow_resize_wt, &wp); |
| 517 | 443 | } |
| r2959 | r2960 | |
| 524 | 450 | static OSDWORK_CALLBACK( sdlwindow_clear_surface_wt ) |
| 525 | 451 | { |
| 526 | 452 | worker_param *wp = (worker_param *) param; |
| 527 | | //sdl_window_info *window = sdl_window_list; |
| 528 | 453 | sdl_window_info *window = wp->window; |
| 529 | | int i; |
| 530 | 454 | |
| 531 | 455 | ASSERT_WINDOW_THREAD(); |
| 532 | 456 | |
| 533 | | for (i=0;i < wp->times; i++) |
| 534 | | { |
| 535 | | if (SDL_MUSTLOCK(window->sdlsurf)) SDL_LockSurface(window->sdlsurf); |
| 536 | | |
| 537 | | memset(window->sdlsurf->pixels, 0, window->sdlsurf->h * window->sdlsurf->pitch); |
| 538 | | if (SDL_MUSTLOCK(window->sdlsurf)) SDL_UnlockSurface(window->sdlsurf); |
| 539 | | |
| 540 | | SDL_Flip(window->sdlsurf); |
| 541 | | } |
| 542 | | |
| 457 | draw.window_clear(window); |
| 543 | 458 | free(wp); |
| 544 | 459 | return NULL; |
| 545 | 460 | } |
| 546 | 461 | |
| 547 | | static void sdlwindow_clear_surface(sdl_window_info *window, int times) |
| 462 | static void sdlwindow_clear_surface(sdl_window_info *window) |
| 548 | 463 | { |
| 549 | 464 | worker_param *wp = malloc(sizeof(worker_param)); |
| 550 | 465 | |
| 551 | 466 | clear_worker_param(wp); |
| 552 | 467 | wp->window = window; |
| 553 | | wp->times = times; |
| 554 | 468 | |
| 555 | 469 | if (SDL_ThreadID() == main_threadid) |
| 556 | 470 | { |
| r2959 | r2960 | |
| 580 | 494 | // If we are going fullscreen (leaving windowed) remember our windowed size |
| 581 | 495 | if (!window->fullscreen) |
| 582 | 496 | { |
| 583 | | window->windowed_width = window->sdlsurf->w; |
| 584 | | window->windowed_height = window->sdlsurf->h; |
| 497 | window->windowed_width = window->width; |
| 498 | window->windowed_height = window->height; |
| 585 | 499 | } |
| 586 | 500 | |
| 587 | | // toggle the window mode |
| 588 | | video_config.windowed ^= 1; |
| 589 | | |
| 590 | 501 | (*draw.window_destroy)(window); |
| 591 | 502 | |
| 592 | | window->fullscreen = !video_config.windowed; |
| 503 | // toggle the window mode |
| 504 | window->fullscreen = !window->fullscreen; |
| 593 | 505 | |
| 594 | 506 | complete_create_wt(param, 0); |
| 595 | 507 | |
| 596 | 508 | return NULL; |
| 597 | 509 | } |
| 598 | 510 | |
| 599 | | void sdlwindow_toggle_full_screen(sdl_window_info *window) |
| 511 | void sdlwindow_toggle_full_screen(running_machine *machine, sdl_window_info *window) |
| 600 | 512 | { |
| 601 | 513 | worker_param wp; |
| 602 | 514 | |
| r2959 | r2960 | |
| 608 | 520 | execute_async_wait(&sdlwindow_toggle_full_screen_wt, &wp); |
| 609 | 521 | } |
| 610 | 522 | |
| 611 | | static void sdlwindow_modify_yuv(int dir) |
| 523 | static void sdlwindow_modify_yuv(running_machine *machine, int dir) |
| 612 | 524 | { |
| 613 | | sdl_window_info *window = sdl_window_list; |
| 614 | 525 | int new_yuv_mode = video_config.yuv_mode; |
| 526 | sdl_window_info *window = sdlinput_get_focus_window(machine); |
| 615 | 527 | |
| 616 | 528 | if (dir > 0 && video_config.yuv_mode < VIDEO_YUV_MODE_MAX) |
| 617 | 529 | new_yuv_mode = video_config.yuv_mode + 1; |
| r2959 | r2960 | |
| 623 | 535 | worker_param wp; |
| 624 | 536 | |
| 625 | 537 | clear_worker_param(&wp); |
| 626 | | |
| 627 | 538 | wp.window = window; |
| 628 | | |
| 629 | 539 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 630 | 540 | |
| 631 | 541 | video_config.yuv_mode = new_yuv_mode; |
| 632 | | |
| 633 | 542 | execute_async_wait(&complete_create_wt, &wp); |
| 634 | 543 | |
| 635 | 544 | ui_popup_time(1, "YUV mode %s", yuv_mode_names[video_config.yuv_mode]); |
| r2959 | r2960 | |
| 648 | 557 | return NULL; |
| 649 | 558 | } |
| 650 | 559 | |
| 651 | | void sdlwindow_modify_prescale(sdl_window_info *window, int dir) |
| 560 | void sdlwindow_modify_prescale(running_machine *machine, sdl_window_info *window, int dir) |
| 652 | 561 | { |
| 653 | 562 | worker_param wp; |
| 654 | 563 | int new_prescale = video_config.prescale; |
| r2959 | r2960 | |
| 664 | 573 | |
| 665 | 574 | if (new_prescale != video_config.prescale) |
| 666 | 575 | { |
| 667 | | if (!video_config.windowed && video_config.switchres) |
| 576 | if (window->fullscreen && video_config.switchres) |
| 668 | 577 | { |
| 669 | 578 | execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp); |
| 670 | 579 | |
| r2959 | r2960 | |
| 682 | 591 | } |
| 683 | 592 | } |
| 684 | 593 | |
| 685 | | void sdlwindow_modify_effect(sdl_window_info *window, int dir) |
| 594 | void sdlwindow_modify_effect(running_machine *machine, sdl_window_info *window, int dir) |
| 686 | 595 | { |
| 687 | 596 | |
| 688 | 597 | if (video_config.mode == VIDEO_MODE_SOFT) |
| 689 | 598 | { |
| 690 | | sdlwindow_modify_yuv(dir); |
| 599 | sdlwindow_modify_yuv(machine, dir); |
| 691 | 600 | return; |
| 692 | 601 | } |
| 693 | 602 | #if USE_OPENGL |
| r2959 | r2960 | |
| 716 | 625 | #endif |
| 717 | 626 | } |
| 718 | 627 | |
| 719 | | void sdlwindow_toggle_draw(sdl_window_info *window) |
| 628 | void sdlwindow_toggle_draw(running_machine *machine, sdl_window_info *window) |
| 720 | 629 | { |
| 721 | 630 | #if USE_OPENGL |
| 722 | 631 | worker_param wp; |
| r2959 | r2960 | |
| 724 | 633 | // If we are not fullscreen (windowed) remember our windowed size |
| 725 | 634 | if (!window->fullscreen) |
| 726 | 635 | { |
| 727 | | window->windowed_width = window->sdlsurf->w; |
| 728 | | window->windowed_height = window->sdlsurf->h; |
| 636 | window->windowed_width = window->width; |
| 637 | window->windowed_height = window->height; |
| 729 | 638 | } |
| 730 | 639 | |
| 731 | 640 | clear_worker_param(&wp); |
| r2959 | r2960 | |
| 757 | 666 | // (main or window thread) |
| 758 | 667 | //============================================================ |
| 759 | 668 | |
| 760 | | static void sdlwindow_update_cursor_state(void) |
| 669 | static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window) |
| 761 | 670 | { |
| 671 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 762 | 672 | // do not do mouse capture if the debugger's enabled to avoid |
| 763 | 673 | // the possibility of losing control |
| 764 | 674 | if (!options_get_bool(mame_options(), OPTION_DEBUG)) |
| 765 | 675 | { |
| 766 | | if (video_config.windowed && !sdlinput_should_hide_mouse()) |
| 676 | if (!window->fullscreen && !sdlinput_should_hide_mouse(machine)) |
| 767 | 677 | { |
| 768 | 678 | SDL_ShowCursor(SDL_ENABLE); |
| 679 | if (SDL_GetWindowGrab(window->window_id )) |
| 680 | SDL_SetWindowGrab(window->window_id, 0); |
| 681 | } |
| 682 | else |
| 683 | { |
| 684 | SDL_ShowCursor(SDL_DISABLE); |
| 685 | if (!SDL_GetWindowGrab(window->window_id)) |
| 686 | SDL_SetWindowGrab(window->window_id, 1); |
| 687 | } |
| 688 | } |
| 689 | #else |
| 690 | // do not do mouse capture if the debugger's enabled to avoid |
| 691 | // the possibility of losing control |
| 692 | if (!options_get_bool(mame_options(), OPTION_DEBUG)) |
| 693 | { |
| 694 | if (!window->fullscreen && !sdlinput_should_hide_mouse(machine)) |
| 695 | { |
| 696 | SDL_ShowCursor(SDL_ENABLE); |
| 769 | 697 | if (SDL_WM_GrabInput(SDL_GRAB_QUERY)) |
| 770 | 698 | { |
| 771 | 699 | SDL_WM_GrabInput(SDL_GRAB_OFF); |
| r2959 | r2960 | |
| 780 | 708 | } |
| 781 | 709 | } |
| 782 | 710 | } |
| 711 | #endif |
| 783 | 712 | } |
| 784 | 713 | |
| 785 | 714 | //============================================================ |
| r2959 | r2960 | |
| 871 | 800 | |
| 872 | 801 | static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt ) |
| 873 | 802 | { |
| 874 | | worker_param *wp = (worker_param *) param; |
| 875 | | sdl_window_info *window = wp->window; |
| 803 | worker_param * wp = (worker_param *) param; |
| 804 | sdl_window_info * window = wp->window; |
| 876 | 805 | |
| 877 | 806 | ASSERT_WINDOW_THREAD(); |
| 878 | 807 | |
| 879 | | if (window->sdlsurf) |
| 880 | | { |
| 881 | | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 882 | | // Will be done by SDL on next call to SetVideoMode |
| 883 | | SDL_FreeSurface(window->sdlsurf); |
| 884 | | #endif |
| 885 | | window->sdlsurf = NULL; |
| 886 | | } |
| 887 | | |
| 888 | 808 | // free the textures etc |
| 889 | 809 | (*draw.window_destroy)(window); |
| 890 | 810 | |
| r2959 | r2960 | |
| 953 | 873 | minimum_height -= 4; |
| 954 | 874 | } |
| 955 | 875 | |
| 876 | #if (SDL_VERSION_ATLEAST(1,3,0)) |
| 877 | // FIXME: Mode switching not supported! |
| 878 | modes = NULL; |
| 879 | #else |
| 956 | 880 | modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_DOUBLEBUF); |
| 957 | | |
| 881 | #endif |
| 882 | |
| 958 | 883 | if (modes == (SDL_Rect **)0) |
| 959 | 884 | { |
| 960 | 885 | mame_printf_error("SDL: No modes available?!\n"); |
| r2959 | r2960 | |
| 999 | 924 | } |
| 1000 | 925 | |
| 1001 | 926 | |
| 1002 | | |
| 1003 | 927 | //============================================================ |
| 1004 | 928 | // sdlwindow_video_window_update |
| 1005 | 929 | // (main thread) |
| 1006 | 930 | //============================================================ |
| 1007 | 931 | |
| 1008 | | void sdlwindow_video_window_update(sdl_window_info *window) |
| 932 | void sdlwindow_video_window_update(running_machine *machine, sdl_window_info *window) |
| 1009 | 933 | { |
| 1010 | 934 | |
| 1011 | 935 | ASSERT_MAIN_THREAD(); |
| 1012 | 936 | |
| 1013 | 937 | // adjust the cursor state |
| 1014 | | sdlwindow_update_cursor_state(); |
| 938 | sdlwindow_update_cursor_state(machine, window); |
| 1015 | 939 | |
| 1016 | 940 | // if we're visible and running and not in the middle of a resize, draw |
| 1017 | 941 | if (window->target != NULL) |
| r2959 | r2960 | |
| 1027 | 951 | window->minheight = tempheight; |
| 1028 | 952 | if (!window->fullscreen) |
| 1029 | 953 | { |
| 1030 | | sdl_info *sdl = window->dxdata; |
| 1031 | | sdlwindow_blit_surface_size(window, window->sdlsurf->w, window->sdlsurf->h); |
| 1032 | | sdlwindow_resize(window, sdl->blitwidth, sdl->blitheight); |
| 954 | sdlwindow_blit_surface_size(window, window->width, window->height); |
| 955 | sdlwindow_resize(window, window->blitwidth, window->blitheight); |
| 1033 | 956 | } |
| 1034 | 957 | else if (video_config.switchres) |
| 1035 | 958 | { |
| 1036 | 959 | pick_best_mode(window, &tempwidth, &tempheight); |
| 1037 | 960 | sdlwindow_resize(window, tempwidth, tempheight); |
| 1038 | 961 | } |
| 1039 | | |
| 1040 | | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 1041 | | { |
| 1042 | | yuv_overlay_init(window); |
| 1043 | | } |
| 1044 | 962 | } |
| 1045 | | |
| 963 | |
| 1046 | 964 | // this: 'osd_lock_acquire', just to 'see' if rendering was still happening |
| 1047 | 965 | // is invalid. |
| 1048 | 966 | // 'osd_lock_acquire' puts us to the waiting queue and we will miss to be in sync with real-time |
| r2959 | r2960 | |
| 1068 | 986 | osd_lock_release(window->render_lock); |
| 1069 | 987 | |
| 1070 | 988 | // ensure the target bounds are up-to-date, and then get the primitives |
| 1071 | | primlist = (*draw.window_get_primitives)(window); |
| 989 | primlist = draw.window_get_primitives(window); |
| 1072 | 990 | |
| 1073 | 991 | // and redraw now |
| 1074 | 992 | |
| 1075 | 993 | wp.list = primlist; |
| 1076 | 994 | wp.window = window; |
| 995 | wp.machine = machine; |
| 1077 | 996 | |
| 1078 | 997 | execute_async(&draw_video_contents_wt, &wp); |
| 1079 | 998 | } |
| r2959 | r2960 | |
| 1105 | 1024 | window->start_viewscreen=viewindex; |
| 1106 | 1025 | } |
| 1107 | 1026 | |
| 1108 | | |
| 1109 | 1027 | //============================================================ |
| 1110 | 1028 | // complete_create |
| 1111 | 1029 | // (window thread) |
| r2959 | r2960 | |
| 1113 | 1031 | |
| 1114 | 1032 | static OSDWORK_CALLBACK( complete_create_wt ) |
| 1115 | 1033 | { |
| 1116 | | worker_param *wp = (worker_param *) param; |
| 1117 | | sdl_window_info *window = wp->window; |
| 1034 | worker_param * wp = (worker_param *) param; |
| 1035 | sdl_window_info * window = wp->window; |
| 1036 | |
| 1118 | 1037 | int tempwidth, tempheight; |
| 1119 | 1038 | static int result[2] = {0,1}; |
| 1120 | 1039 | |
| r2959 | r2960 | |
| 1123 | 1042 | |
| 1124 | 1043 | if (window->fullscreen) |
| 1125 | 1044 | { |
| 1126 | | |
| 1127 | | window->extra_flags = SDL_FULLSCREEN; |
| 1128 | 1045 | // default to the current mode exactly |
| 1129 | 1046 | tempwidth = window->monitor->monitor_width; |
| 1130 | 1047 | tempheight = window->monitor->monitor_height; |
| r2959 | r2960 | |
| 1135 | 1052 | } |
| 1136 | 1053 | else if (window->windowed_width) |
| 1137 | 1054 | { |
| 1138 | | window->extra_flags = SDL_RESIZABLE; |
| 1139 | 1055 | // if we have a remembered size force the new window size to it |
| 1140 | 1056 | tempwidth = window->windowed_width; |
| 1141 | 1057 | tempheight = window->windowed_height; |
| 1142 | 1058 | } |
| 1143 | 1059 | else |
| 1144 | 1060 | { |
| 1145 | | window->extra_flags = SDL_RESIZABLE; |
| 1146 | | |
| 1147 | 1061 | if (window->startmaximized) |
| 1148 | 1062 | { |
| 1149 | 1063 | tempwidth = tempheight = 0; |
| r2959 | r2960 | |
| 1162 | 1076 | } |
| 1163 | 1077 | } |
| 1164 | 1078 | |
| 1165 | | #ifndef NO_OPENGL |
| 1166 | | if (video_config.mode == VIDEO_MODE_OPENGL) |
| 1167 | | { |
| 1168 | | window->extra_flags |= SDL_OPENGL; |
| 1169 | | |
| 1170 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 1171 | | |
| 1172 | | #if (SDL_VERSION_ATLEAST(1,2,10)) |
| 1173 | | #if (!SDL_VERSION_ATLEAST(1,3,0)) |
| 1174 | | if (options_get_bool(mame_options(), SDLOPTION_WAITVSYNC)) |
| 1175 | | { |
| 1176 | | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
| 1177 | | } |
| 1178 | | else |
| 1179 | | { |
| 1180 | | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0); |
| 1181 | | } |
| 1182 | | #endif |
| 1183 | | #endif |
| 1184 | | } |
| 1185 | | |
| 1186 | | #ifdef USE_DISPATCH_GL |
| 1187 | | if ((video_config.mode == VIDEO_MODE_OPENGL) && !dll_loaded) |
| 1188 | | { |
| 1189 | | /* |
| 1190 | | * directfb and and x11 use this env var |
| 1191 | | * SDL_VIDEO_GL_DRIVER |
| 1192 | | */ |
| 1193 | | const char *e; |
| 1194 | | |
| 1195 | | e=getenv(SDLENV_GL_LIB); |
| 1196 | | |
| 1197 | | #ifdef SDLMAME_MACOSX |
| 1198 | | /* Vas Crabb: Default GL-lib for MACOSX */ |
| 1199 | | if (!e) |
| 1200 | | e = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"; |
| 1201 | | #endif |
| 1202 | | if (SDL_GL_LoadLibrary(e) != 0) // Load library (default for e==NULL |
| 1203 | | { |
| 1204 | | fatalerror("Unable to load default library: %s\n", e); |
| 1205 | | } |
| 1206 | | mame_printf_verbose("Loaded opengl shared library: %s\n", e ? e : "<default>"); |
| 1207 | | gl_dispatch = auto_malloc(sizeof(osd_gl_dispatch)); |
| 1208 | | dll_loaded=1; |
| 1209 | | } |
| 1210 | | #endif |
| 1211 | | #endif |
| 1212 | | // create the SDL surface (which creates the window in windowed mode) |
| 1213 | | if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE) |
| 1214 | | window->sdlsurf = SDL_SetVideoMode(tempwidth, tempheight, |
| 1215 | | 0, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT | window->extra_flags); |
| 1216 | | else |
| 1217 | | window->sdlsurf = SDL_SetVideoMode(tempwidth, tempheight, |
| 1218 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT |window->extra_flags); |
| 1219 | | |
| 1220 | | if (!window->sdlsurf) |
| 1221 | | return (void *) &result[1]; |
| 1222 | | |
| 1223 | | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(window->sdlsurf->flags & SDL_OPENGL) ) |
| 1224 | | { |
| 1225 | | fprintf(stderr, "OpenGL not supported on this driver!\n"); |
| 1226 | | return (void *) &result[1]; |
| 1227 | | } |
| 1228 | | |
| 1229 | 1079 | // initialize the drawing backend |
| 1230 | | if ((*draw.window_init)(window)) |
| 1080 | if ((*draw.window_create)(window, tempwidth, tempheight)) |
| 1231 | 1081 | return (void *) &result[1]; |
| 1232 | 1082 | |
| 1233 | | if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE) |
| 1234 | | { |
| 1235 | | yuv_overlay_init(window); |
| 1236 | | } |
| 1237 | | |
| 1238 | | // set the window title |
| 1239 | | SDL_WM_SetCaption(window->title, "SDLMAME"); |
| 1240 | | |
| 1241 | 1083 | return (void *) &result[0]; |
| 1242 | 1084 | } |
| 1243 | 1085 | |
| r2959 | r2960 | |
| 1261 | 1103 | |
| 1262 | 1104 | return res; |
| 1263 | 1105 | } |
| 1264 | | #endif |
| 1265 | 1106 | |
| 1266 | | static OSDWORK_CALLBACK( draw_video_contents_wt ) |
| 1107 | static void measure_fps(sdl_window_info *window, UINT32 dc, int update) |
| 1267 | 1108 | { |
| 1268 | | #ifndef SDLMAME_WIN32 |
| 1269 | 1109 | const unsigned long frames_skip4fps = 100; |
| 1270 | 1110 | static int64_t lastTime=0, sumdt=0, startTime=0; |
| 1271 | 1111 | static unsigned long frames = 0; |
| 1272 | 1112 | int64_t currentTime, t0; |
| 1273 | 1113 | double dt; |
| 1274 | | #endif |
| 1114 | |
| 1115 | t0 = getusecs(); |
| 1116 | |
| 1117 | (*draw.window_draw)(window, dc, update); |
| 1118 | |
| 1119 | frames++; |
| 1120 | currentTime = getusecs(); |
| 1121 | if(startTime==0||frames==frames_skip4fps) |
| 1122 | startTime=currentTime; |
| 1123 | if( frames>=frames_skip4fps ) |
| 1124 | sumdt+=currentTime-t0; |
| 1125 | if( (currentTime-lastTime)>1L*1000000L && frames>frames_skip4fps ) |
| 1126 | { |
| 1127 | dt = (double)( ((currentTime-startTime)/10000L) ) / 100.0 ; // in decimale sec. |
| 1128 | mame_printf_info("%6.2lfs, %4lu F, " |
| 1129 | "avrg game: %5.2lf FPS %.2lf ms/f, " |
| 1130 | "avrg video: %5.2lf FPS %.2lf ms/f, " |
| 1131 | "last video: %5.2lf FPS %.2lf ms/f\n", |
| 1132 | dt, frames-frames_skip4fps, |
| 1133 | (double)(frames-frames_skip4fps)/dt, // avrg game fps |
| 1134 | ( (currentTime-startTime) / ((frames-frames_skip4fps)) ) /1000.0, |
| 1135 | (double)(frames-frames_skip4fps)/((double)(sumdt/10000L)/100.0), // avrg vid fps |
| 1136 | ( sumdt / ((frames-frames_skip4fps)) ) /1000.0, |
| 1137 | 1.0/((currentTime-t0) / 1000000.0), // this vid fps |
| 1138 | (currentTime-t0) / 1000.0 |
| 1139 | ); |
| 1140 | lastTime = currentTime; |
| 1141 | } |
| 1142 | } |
| 1143 | #else |
| 1144 | static void measure_fps(sdl_window_info *window, UINT32 dc, int update) |
| 1145 | { |
| 1146 | (*draw.window_draw)(window, dc, update); |
| 1147 | } |
| 1148 | #endif |
| 1149 | |
| 1150 | static OSDWORK_CALLBACK( draw_video_contents_wt ) |
| 1151 | { |
| 1275 | 1152 | UINT32 dc = 0; |
| 1276 | 1153 | int update = 1; |
| 1277 | 1154 | worker_param *wp = (worker_param *) param; |
| 1278 | 1155 | sdl_window_info *window = wp->window; |
| 1279 | 1156 | |
| 1280 | 1157 | ASSERT_REDRAW_THREAD(); |
| 1281 | | #ifdef SDLMAME_WIN32 |
| 1282 | | sdlinput_process_events_buf(); |
| 1283 | | #endif |
| 1158 | |
| 1159 | // Some configurations require events to be polled in the worker thread |
| 1160 | sdlinput_process_events_buf(wp->machine); |
| 1284 | 1161 | |
| 1285 | 1162 | window->primlist = wp->list; |
| 1286 | 1163 | osd_lock_acquire(window->render_lock); |
| 1287 | | if (window->sdlsurf) |
| 1288 | | { |
| 1289 | | // if no bitmap, just fill |
| 1290 | | if (window->primlist == NULL) |
| 1291 | | { |
| 1292 | | } |
| 1293 | 1164 | |
| 1294 | | // otherwise, render with our drawing system |
| 1295 | | else |
| 1296 | | { |
| 1297 | | #ifndef SDLMAME_WIN32 |
| 1298 | | if( video_config.perftest ) |
| 1299 | | { |
| 1300 | | t0 = getusecs(); |
| 1301 | | |
| 1302 | | (*draw.window_draw)(window, dc, update); |
| 1303 | | |
| 1304 | | frames++; |
| 1305 | | currentTime = getusecs(); |
| 1306 | | if(startTime==0||frames==frames_skip4fps) |
| 1307 | | startTime=currentTime; |
| 1308 | | if( frames>=frames_skip4fps ) |
| 1309 | | sumdt+=currentTime-t0; |
| 1310 | | if( (currentTime-lastTime)>1L*1000000L && frames>frames_skip4fps ) |
| 1311 | | { |
| 1312 | | dt = (double)( ((currentTime-startTime)/10000L) ) / 100.0 ; // in decimale sec. |
| 1313 | | mame_printf_info("%6.2lfs, %4lu F, " |
| 1314 | | "avrg game: %5.2lf FPS %.2lf ms/f, " |
| 1315 | | "avrg video: %5.2lf FPS %.2lf ms/f, " |
| 1316 | | "last video: %5.2lf FPS %.2lf ms/f\n", |
| 1317 | | dt, frames-frames_skip4fps, |
| 1318 | | (double)(frames-frames_skip4fps)/dt, // avrg game fps |
| 1319 | | ( (currentTime-startTime) / ((frames-frames_skip4fps)) ) /1000.0, |
| 1320 | | (double)(frames-frames_skip4fps)/((double)(sumdt/10000L)/100.0), // avrg vid fps |
| 1321 | | ( sumdt / ((frames-frames_skip4fps)) ) /1000.0, |
| 1322 | | 1.0/((currentTime-t0) / 1000000.0), // this vid fps |
| 1323 | | (currentTime-t0) / 1000.0 |
| 1324 | | ); |
| 1325 | | lastTime = currentTime; |
| 1326 | | } |
| 1327 | | } |
| 1328 | | else |
| 1329 | | #endif |
| 1330 | | { |
| 1331 | | (*draw.window_draw)(window, dc, update); |
| 1332 | | } |
| 1333 | | } |
| 1165 | // if no bitmap, just fill |
| 1166 | if (window->primlist == NULL) |
| 1167 | { |
| 1334 | 1168 | } |
| 1169 | // otherwise, render with our drawing system |
| 1170 | else |
| 1171 | { |
| 1172 | if( video_config.perftest ) |
| 1173 | measure_fps(window, dc, update); |
| 1174 | else |
| 1175 | (*draw.window_draw)(window, dc, update); |
| 1176 | } |
| 1335 | 1177 | osd_lock_release(window->render_lock); |
| 1336 | 1178 | free(wp); |
| 1337 | 1179 | |
src/osd/sdl/debugosx.c
| r2959 | r2960 | |
| 33 | 33 | #include "debug/debugcon.h" |
| 34 | 34 | #include "debug/debugcpu.h" |
| 35 | 35 | #include "debugger.h" |
| 36 | #include "uiinput.h" |
| 36 | 37 | |
| 37 | 38 | // MAMEOS headers |
| 38 | 39 | #include "debugwin.h" |
| r2959 | r2960 | |
| 489 | 490 | { |
| 490 | 491 | // see if the interrupt key is pressed and break if it is |
| 491 | 492 | temporarily_fake_that_we_are_not_visible = TRUE; |
| 492 | | if (input_ui_pressed(Machine, IPT_UI_DEBUG_BREAK)) |
| 493 | if (ui_input_pressed(Machine, IPT_UI_DEBUG_BREAK)) |
| 493 | 494 | { |
| 494 | 495 | debugwin_info *info; |
| 495 | 496 | HIViewRef focuswnd; |
| r2959 | r2960 | |
| 1201 | 1202 | // fill out the scroll info struct for the vertical scrollbar |
| 1202 | 1203 | if ( show_vscroll ) |
| 1203 | 1204 | { |
| 1205 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1204 | 1206 | HIViewSetMinimum(info->vscroll,0); |
| 1205 | 1207 | HIViewSetMaximum(info->vscroll,total_rows-visible_rows); |
| 1206 | 1208 | HIViewSetValue(info->vscroll,top_row); |
| 1207 | 1209 | HIViewSetViewSize(info->vscroll,visible_rows); |
| 1210 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1211 | SetControl32BitMinimum(info->vscroll,0); |
| 1212 | SetControl32BitMaximum(info->vscroll,total_rows-visible_rows); |
| 1213 | SetControl32BitValue(info->vscroll,top_row); |
| 1214 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1208 | 1215 | } |
| 1209 | 1216 | |
| 1210 | 1217 | // fill out the scroll info struct for the horizontal scrollbar |
| 1211 | 1218 | if ( show_hscroll ) |
| 1212 | 1219 | { |
| 1220 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1213 | 1221 | HIViewSetMinimum(info->hscroll,0); |
| 1214 | 1222 | HIViewSetMaximum(info->hscroll,total_cols-visible_cols); |
| 1215 | 1223 | HIViewSetValue(info->hscroll,left_col); |
| 1216 | 1224 | HIViewSetViewSize(info->hscroll,visible_cols); |
| 1225 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1226 | SetControl32BitMinimum(info->hscroll,0); |
| 1227 | SetControl32BitMaximum(info->hscroll,total_cols-visible_cols); |
| 1228 | SetControl32BitValue(info->hscroll,left_col); |
| 1229 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1217 | 1230 | } |
| 1218 | 1231 | |
| 1219 | 1232 | // update window info |
| r2959 | r2960 | |
| 1300 | 1313 | |
| 1301 | 1314 | isHorz = (inView == info->hscroll) ? 1 : 0; |
| 1302 | 1315 | |
| 1316 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1303 | 1317 | maxval = HIViewGetMaximum(inView); |
| 1304 | 1318 | result = HIViewGetValue(inView); |
| 1319 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1320 | maxval = GetControl32BitMaximum(inView); |
| 1321 | result = GetControl32BitValue(inView); |
| 1322 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1305 | 1323 | |
| 1306 | 1324 | switch( partCode ) |
| 1307 | 1325 | { |
| r2959 | r2960 | |
| 1563 | 1581 | |
| 1564 | 1582 | if ( axis == kEventMouseWheelAxisX && info->hscroll != NULL ) |
| 1565 | 1583 | { |
| 1584 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1566 | 1585 | maxval = HIViewGetMaximum(info->hscroll); |
| 1567 | 1586 | result = HIViewGetValue(info->hscroll); |
| 1587 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1588 | maxval = GetControl32BitMaximum(info->hscroll); |
| 1589 | result = GetControl32BitValue(info->hscroll); |
| 1590 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1568 | 1591 | } |
| 1569 | 1592 | else if ( axis == kEventMouseWheelAxisY && info->vscroll != NULL ) |
| 1570 | 1593 | { |
| 1594 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1571 | 1595 | maxval = HIViewGetMaximum(info->vscroll); |
| 1572 | 1596 | result = HIViewGetValue(info->vscroll); |
| 1597 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1598 | maxval = GetControl32BitMaximum(info->vscroll); |
| 1599 | result = GetControl32BitValue(info->vscroll); |
| 1600 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1573 | 1601 | } |
| 1574 | 1602 | |
| 1575 | 1603 | result -= delta; |
| r2959 | r2960 | |
| 2198 | 2226 | } |
| 2199 | 2227 | |
| 2200 | 2228 | SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu); |
| 2229 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2201 | 2230 | HIViewSetMinimum(info->otherwnd[0], 1); |
| 2202 | 2231 | HIViewSetMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2203 | 2232 | HIViewSetValue(info->otherwnd[0],cursel); |
| 2233 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2234 | SetControl32BitMinimum(info->otherwnd[0], 1); |
| 2235 | SetControl32BitMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2236 | SetControl32BitValue(info->otherwnd[0],cursel); |
| 2237 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2204 | 2238 | |
| 2205 | 2239 | // set the child functions |
| 2206 | 2240 | info->recompute_children = memory_recompute_children; |
| r2959 | r2960 | |
| 2370 | 2404 | { |
| 2371 | 2405 | case OSX_POPUP_COMMAND: |
| 2372 | 2406 | { |
| 2407 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2373 | 2408 | int sel = HIViewGetValue(info->otherwnd[0]); |
| 2409 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2410 | int sel = GetControl32BitValue(info->otherwnd[0]); |
| 2411 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2374 | 2412 | |
| 2375 | 2413 | if ( sel > 0 ) |
| 2376 | 2414 | { |
| r2959 | r2960 | |
| 2692 | 2730 | } |
| 2693 | 2731 | |
| 2694 | 2732 | SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu); |
| 2733 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2695 | 2734 | HIViewSetMinimum(info->otherwnd[0], 1); |
| 2696 | 2735 | HIViewSetMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2697 | 2736 | HIViewSetValue(info->otherwnd[0],cursel); |
| 2737 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2738 | SetControl32BitMinimum(info->otherwnd[0], 1); |
| 2739 | SetControl32BitMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2740 | SetControl32BitValue(info->otherwnd[0],cursel); |
| 2741 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2698 | 2742 | |
| 2699 | 2743 | // set the child functions |
| 2700 | 2744 | info->recompute_children = disasm_recompute_children; |
| r2959 | r2960 | |
| 2861 | 2905 | { |
| 2862 | 2906 | case OSX_POPUP_COMMAND: |
| 2863 | 2907 | { |
| 2908 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2864 | 2909 | int sel = HIViewGetValue(info->otherwnd[0]); |
| 2910 | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2911 | int sel = GetControl32BitValue(info->otherwnd[0]); |
| 2912 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2865 | 2913 | |
| 2866 | 2914 | if ( sel > 0 ) |
| 2867 | 2915 | { |
| r2959 | r2960 | |
| 3537 | 3585 | int ignoreme; |
| 3538 | 3586 | |
| 3539 | 3587 | /* ignore any keys that are received while the debug key is down */ |
| 3540 | | ignoreme = input_ui_pressed(Machine, IPT_UI_DEBUG_BREAK); |
| 3588 | ignoreme = ui_input_pressed(Machine, IPT_UI_DEBUG_BREAK); |
| 3541 | 3589 | if (ignoreme) |
| 3542 | 3590 | return 1; |
| 3543 | 3591 | |