trunk/src/osd/sdl/draw13.c
| r243363 | r243364 | |
| 163 | 163 | texture_info *texture_update(const render_primitive &prim); |
| 164 | 164 | |
| 165 | 165 | INT32 m_blittimer; |
| 166 | | UINT32 m_extra_flags; |
| 167 | 166 | |
| 168 | | |
| 169 | 167 | #if (SDLMAME_SDL2) |
| 170 | | // Original display_mode |
| 171 | | SDL_DisplayMode m_original_mode; |
| 172 | | |
| 173 | 168 | SDL_GLContext m_gl_context_id; |
| 174 | 169 | #else |
| 175 | 170 | // SDL surface |
| r243363 | r243364 | |
| 583 | 578 | |
| 584 | 579 | int sdl_info13::create(int width, int height) |
| 585 | 580 | { |
| 586 | | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 587 | | * to disable panning. This has to be done before every invocation of mame. |
| 588 | | * |
| 589 | | * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0 |
| 590 | | * |
| 591 | | */ |
| 592 | | osd_printf_verbose("Enter sdl_info::create\n"); |
| 593 | | |
| 594 | 581 | #if (SDLMAME_SDL2) |
| 595 | | |
| 596 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 597 | | { |
| 598 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 599 | | |
| 600 | | /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to |
| 601 | | * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension. |
| 602 | | * |
| 603 | | * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 ); |
| 604 | | * |
| 605 | | */ |
| 606 | | m_extra_flags = SDL_WINDOW_OPENGL; |
| 607 | | } |
| 608 | | else |
| 609 | | m_extra_flags = 0; |
| 610 | | |
| 611 | | // create the SDL window |
| 612 | | // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS |
| 613 | | m_extra_flags |= (window().fullscreen() ? |
| 614 | | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 615 | | |
| 616 | | #if defined(SDLMAME_WIN32) |
| 617 | | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 618 | | #endif |
| 619 | | // create the SDL window |
| 620 | | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 621 | | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 622 | | width, height, m_extra_flags); |
| 623 | | //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 624 | | // width, height, m_extra_flags); |
| 625 | | |
| 626 | | if (!window().m_sdl_window ) |
| 627 | | { |
| 628 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 629 | | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 630 | | else |
| 631 | | osd_printf_error("Window creation failed: %s\n", SDL_GetError()); |
| 632 | | return 1; |
| 633 | | } |
| 634 | | |
| 635 | | if (window().fullscreen() && video_config.switchres) |
| 636 | | { |
| 637 | | SDL_DisplayMode mode; |
| 638 | | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 639 | | SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); |
| 640 | | m_original_mode = mode; |
| 641 | | mode.w = width; |
| 642 | | mode.h = height; |
| 643 | | if (window().m_refresh) |
| 644 | | mode.refresh_rate = window().m_refresh; |
| 645 | | |
| 646 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 647 | | #ifndef SDLMAME_WIN32 |
| 648 | | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 649 | | * is in place after the mode switch - which will most likely be the case |
| 650 | | * This is a hack to work around a deficiency in SDL2 |
| 651 | | */ |
| 652 | | SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); |
| 653 | | #endif |
| 654 | | } |
| 655 | | else |
| 656 | | { |
| 657 | | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 658 | | } |
| 659 | | |
| 660 | | // show window |
| 661 | | |
| 662 | | SDL_ShowWindow(window().m_sdl_window); |
| 663 | | //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen); |
| 664 | | SDL_RaiseWindow(window().m_sdl_window); |
| 665 | | |
| 666 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 667 | | |
| 668 | 582 | // create renderer |
| 669 | 583 | |
| 670 | 584 | /* Enable bilinear filtering in case it is supported. |
| r243363 | r243364 | |
| 698 | 612 | osd_printf_verbose("Leave sdl_info13::create\n"); |
| 699 | 613 | |
| 700 | 614 | #else |
| 701 | | m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 702 | 615 | |
| 703 | | if (this->check_flag(FLAG_NEEDS_DOUBLEBUF)) |
| 704 | | m_extra_flags |= SDL_DOUBLEBUF; |
| 705 | | if (this->check_flag(FLAG_NEEDS_ASYNCBLIT)) |
| 706 | | m_extra_flags |= SDL_ASYNCBLIT; |
| 707 | | |
| 708 | | if (this->check_flag(FLAG_NEEDS_OPENGL)) |
| 709 | | { |
| 710 | | m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL; |
| 711 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 712 | | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| 713 | | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); |
| 714 | | #endif |
| 715 | | //load_gl_lib(window().machine()); |
| 716 | | } |
| 717 | | |
| 718 | | // create the SDL surface (which creates the window in windowed mode) |
| 719 | | m_sdlsurf = SDL_SetVideoMode(width, height, |
| 720 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 721 | | |
| 722 | | if (!m_sdlsurf) |
| 723 | | return 1; |
| 724 | | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(m_sdlsurf->flags & SDL_OPENGL) ) |
| 725 | | { |
| 726 | | osd_printf_error("OpenGL not supported on this driver!\n"); |
| 727 | | return 1; |
| 728 | | } |
| 729 | | |
| 730 | | window().m_width = m_sdlsurf->w; |
| 731 | | window().m_height = m_sdlsurf->h; |
| 732 | | |
| 733 | | window().m_screen_width = 0; |
| 734 | | window().m_screen_height = 0; |
| 735 | | |
| 736 | | |
| 737 | | // set the window title |
| 738 | | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 739 | | |
| 740 | 616 | #endif |
| 741 | 617 | return 0; |
| 742 | 618 | } |
| r243363 | r243364 | |
| 776 | 652 | if (window().fullscreen() && video_config.switchres) |
| 777 | 653 | { |
| 778 | 654 | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 779 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode |
| 655 | SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode); // Try to set mode |
| 780 | 656 | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 781 | 657 | } |
| 782 | 658 | |
trunk/src/osd/sdl/drawogl.c
| r243363 | r243364 | |
| 222 | 222 | { |
| 223 | 223 | public: |
| 224 | 224 | sdl_info_ogl(sdl_window_info *window) |
| 225 | | : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0), m_extra_flags(0), |
| 225 | : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0), |
| 226 | 226 | #if (SDLMAME_SDL2) |
| 227 | 227 | m_gl_context_id(0), |
| 228 | 228 | #else |
| 229 | | m_sdlsurf(NULL), |
| 230 | 229 | #endif |
| 231 | 230 | m_initialized(0), |
| 232 | 231 | m_last_blendmode(0), |
| r243363 | r243364 | |
| 278 | 277 | void texture_all_disable(); |
| 279 | 278 | |
| 280 | 279 | INT32 m_blittimer; |
| 281 | | UINT32 m_extra_flags; |
| 282 | 280 | |
| 283 | | |
| 284 | 281 | #if (SDLMAME_SDL2) |
| 285 | | // Original display_mode |
| 286 | | SDL_DisplayMode m_original_mode; |
| 287 | | |
| 288 | 282 | SDL_GLContext m_gl_context_id; |
| 289 | 283 | #else |
| 290 | | // SDL surface |
| 291 | | SDL_Surface *m_sdlsurf; |
| 292 | 284 | #endif |
| 293 | 285 | |
| 294 | 286 | int m_initialized; // is everything well initialized, i.e. all GL stuff etc. |
| r243363 | r243364 | |
| 716 | 708 | |
| 717 | 709 | int sdl_info_ogl::create(int width, int height) |
| 718 | 710 | { |
| 719 | | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 720 | | * to disable panning. This has to be done before every invocation of mame. |
| 721 | | * |
| 722 | | * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0 |
| 723 | | * |
| 724 | | */ |
| 725 | | osd_printf_verbose("Enter sdl_info::create\n"); |
| 726 | 711 | |
| 727 | 712 | #if (SDLMAME_SDL2) |
| 728 | | |
| 729 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 730 | | { |
| 731 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 732 | | |
| 733 | | /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to |
| 734 | | * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension. |
| 735 | | * |
| 736 | | * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 ); |
| 737 | | * |
| 738 | | */ |
| 739 | | m_extra_flags = SDL_WINDOW_OPENGL; |
| 740 | | } |
| 741 | | else |
| 742 | | m_extra_flags = 0; |
| 743 | | |
| 744 | | // create the SDL window |
| 745 | | // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS |
| 746 | | m_extra_flags |= (window().fullscreen() ? |
| 747 | | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 748 | | |
| 749 | | #if defined(SDLMAME_WIN32) |
| 750 | | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 751 | | #endif |
| 752 | | // create the SDL window |
| 753 | | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 754 | | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 755 | | width, height, m_extra_flags); |
| 756 | | //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 757 | | // width, height, m_extra_flags); |
| 758 | | |
| 759 | | if (!window().m_sdl_window ) |
| 760 | | { |
| 761 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 762 | | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 763 | | else |
| 764 | | osd_printf_error("Window creation failed: %s\n", SDL_GetError()); |
| 765 | | return 1; |
| 766 | | } |
| 767 | | |
| 768 | | if (window().fullscreen() && video_config.switchres) |
| 769 | | { |
| 770 | | SDL_DisplayMode mode; |
| 771 | | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 772 | | SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); |
| 773 | | m_original_mode = mode; |
| 774 | | mode.w = width; |
| 775 | | mode.h = height; |
| 776 | | if (window().m_refresh) |
| 777 | | mode.refresh_rate = window().m_refresh; |
| 778 | | |
| 779 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 780 | | #ifndef SDLMAME_WIN32 |
| 781 | | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 782 | | * is in place after the mode switch - which will most likely be the case |
| 783 | | * This is a hack to work around a deficiency in SDL2 |
| 784 | | */ |
| 785 | | SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); |
| 786 | | #endif |
| 787 | | } |
| 788 | | else |
| 789 | | { |
| 790 | | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 791 | | } |
| 792 | | |
| 793 | | // show window |
| 794 | | |
| 795 | | SDL_ShowWindow(window().m_sdl_window); |
| 796 | | //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen); |
| 797 | | SDL_RaiseWindow(window().m_sdl_window); |
| 798 | | |
| 799 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 800 | | |
| 801 | 713 | // create renderer |
| 802 | 714 | |
| 803 | 715 | m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window); |
| r243363 | r243364 | |
| 810 | 722 | SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); |
| 811 | 723 | |
| 812 | 724 | #else |
| 813 | | m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 814 | | |
| 815 | | if (this->check_flag(FLAG_NEEDS_DOUBLEBUF)) |
| 816 | | m_extra_flags |= SDL_DOUBLEBUF; |
| 817 | | if (this->check_flag(FLAG_NEEDS_ASYNCBLIT)) |
| 818 | | m_extra_flags |= SDL_ASYNCBLIT; |
| 819 | | |
| 820 | | if (this->check_flag(FLAG_NEEDS_OPENGL)) |
| 821 | | { |
| 822 | | m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL; |
| 823 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 824 | | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| 825 | | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); |
| 826 | | #endif |
| 827 | | //load_gl_lib(window().machine()); |
| 828 | | } |
| 829 | | |
| 830 | | // create the SDL surface (which creates the window in windowed mode) |
| 831 | | m_sdlsurf = SDL_SetVideoMode(width, height, |
| 832 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 833 | | |
| 834 | | if (!m_sdlsurf) |
| 835 | | return 1; |
| 836 | | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(m_sdlsurf->flags & SDL_OPENGL) ) |
| 837 | | { |
| 838 | | osd_printf_error("OpenGL not supported on this driver!\n"); |
| 839 | | return 1; |
| 840 | | } |
| 841 | | |
| 842 | | window().m_width = m_sdlsurf->w; |
| 843 | | window().m_height = m_sdlsurf->h; |
| 844 | | |
| 845 | | window().m_screen_width = 0; |
| 846 | | window().m_screen_height = 0; |
| 847 | | |
| 848 | | |
| 849 | | // set the window title |
| 850 | | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 851 | | |
| 852 | 725 | #endif |
| 853 | 726 | |
| 854 | 727 | m_blittimer = 0; |
| r243363 | r243364 | |
| 887 | 760 | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 888 | 761 | m_blittimer = 3; |
| 889 | 762 | #else |
| 890 | | SDL_FreeSurface(m_sdlsurf); |
| 763 | SDL_FreeSurface(window().m_sdlsurf); |
| 891 | 764 | |
| 892 | | m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 893 | | SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 765 | window().m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 766 | SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags); |
| 894 | 767 | |
| 895 | | window().m_width = m_sdlsurf->w; |
| 896 | | window().m_height = m_sdlsurf->h; |
| 768 | window().m_width = window().m_sdlsurf->w; |
| 769 | window().m_height = window().m_sdlsurf->h; |
| 897 | 770 | #endif |
| 898 | 771 | m_init_context = 1; |
| 899 | 772 | |
| r243363 | r243364 | |
| 917 | 790 | if (window().fullscreen() && video_config.switchres) |
| 918 | 791 | { |
| 919 | 792 | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 920 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode |
| 793 | SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode); // Try to set mode |
| 921 | 794 | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 922 | 795 | } |
| 923 | 796 | |
| 924 | 797 | SDL_DestroyWindow(window().m_sdl_window); |
| 925 | 798 | #else |
| 926 | | if (m_sdlsurf) |
| 799 | if (window().m_sdlsurf) |
| 927 | 800 | { |
| 928 | | SDL_FreeSurface(m_sdlsurf); |
| 929 | | m_sdlsurf = NULL; |
| 801 | SDL_FreeSurface(window().m_sdlsurf); |
| 802 | window().m_sdlsurf = NULL; |
| 930 | 803 | } |
| 931 | 804 | #endif |
| 932 | 805 | } |
trunk/src/osd/sdl/drawsdl.c
| r243363 | r243364 | |
| 53 | 53 | sdl_info(sdl_window_info *w, int extra_flags) |
| 54 | 54 | : osd_renderer(w, extra_flags), |
| 55 | 55 | m_blittimer(0), |
| 56 | | m_extra_flags(0), |
| 57 | 56 | |
| 58 | 57 | #if (SDLMAME_SDL2) |
| 59 | 58 | m_sdl_renderer(NULL), |
| 60 | 59 | m_texture_id(NULL), |
| 61 | 60 | #else |
| 62 | | m_sdlsurf(NULL), |
| 63 | 61 | m_yuvsurf(NULL), |
| 64 | 62 | #endif |
| 65 | 63 | m_yuv_lookup(NULL), |
| r243363 | r243364 | |
| 92 | 90 | #endif |
| 93 | 91 | |
| 94 | 92 | INT32 m_blittimer; |
| 95 | | UINT32 m_extra_flags; |
| 96 | 93 | |
| 97 | 94 | #if (SDLMAME_SDL2) |
| 98 | | // Original display_mode |
| 99 | | SDL_DisplayMode m_original_mode; |
| 100 | | |
| 101 | 95 | SDL_Renderer *m_sdl_renderer; |
| 102 | 96 | SDL_Texture *m_texture_id; |
| 103 | 97 | #else |
| 104 | | // SDL surface |
| 105 | | SDL_Surface *m_sdlsurf; |
| 106 | 98 | SDL_Overlay *m_yuvsurf; |
| 107 | 99 | #endif |
| 108 | 100 | |
| r243363 | r243364 | |
| 347 | 339 | m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); |
| 348 | 340 | |
| 349 | 341 | m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, |
| 350 | | sdl_sm->pixel_format, m_sdlsurf); |
| 342 | sdl_sm->pixel_format, window().m_sdlsurf); |
| 351 | 343 | |
| 352 | 344 | if ( m_yuvsurf == NULL ) { |
| 353 | 345 | osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); |
| r243363 | r243364 | |
| 429 | 421 | |
| 430 | 422 | int sdl_info::create(int width, int height) |
| 431 | 423 | { |
| 432 | | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 433 | | * to disable panning. This has to be done before every invocation of mame. |
| 434 | | * |
| 435 | | * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0 |
| 436 | | * |
| 437 | | */ |
| 438 | 424 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 439 | 425 | |
| 440 | | osd_printf_verbose("Enter sdl_info::create\n"); |
| 441 | | |
| 442 | 426 | #if (SDLMAME_SDL2) |
| 443 | 427 | |
| 444 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 445 | | { |
| 446 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 447 | | |
| 448 | | /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to |
| 449 | | * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension. |
| 450 | | * |
| 451 | | * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 ); |
| 452 | | * |
| 453 | | */ |
| 454 | | m_extra_flags = SDL_WINDOW_OPENGL; |
| 455 | | } |
| 456 | | else |
| 457 | | m_extra_flags = 0; |
| 458 | | |
| 459 | | // create the SDL window |
| 460 | | // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS |
| 461 | | m_extra_flags |= (window().fullscreen() ? |
| 462 | | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 463 | | |
| 464 | | #if defined(SDLMAME_WIN32) |
| 465 | | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 466 | | #endif |
| 467 | | // create the SDL window |
| 468 | | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 469 | | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 470 | | width, height, m_extra_flags); |
| 471 | | //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 472 | | // width, height, m_extra_flags); |
| 473 | | |
| 474 | | if (!window().m_sdl_window ) |
| 475 | | { |
| 476 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 477 | | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 478 | | else |
| 479 | | osd_printf_error("Window creation failed: %s\n", SDL_GetError()); |
| 480 | | return 1; |
| 481 | | } |
| 482 | | |
| 483 | | if (window().fullscreen() && video_config.switchres) |
| 484 | | { |
| 485 | | SDL_DisplayMode mode; |
| 486 | | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 487 | | SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); |
| 488 | | m_original_mode = mode; |
| 489 | | mode.w = width; |
| 490 | | mode.h = height; |
| 491 | | if (window().m_refresh) |
| 492 | | mode.refresh_rate = window().m_refresh; |
| 493 | | |
| 494 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 495 | | #ifndef SDLMAME_WIN32 |
| 496 | | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 497 | | * is in place after the mode switch - which will most likely be the case |
| 498 | | * This is a hack to work around a deficiency in SDL2 |
| 499 | | */ |
| 500 | | SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); |
| 501 | | #endif |
| 502 | | } |
| 503 | | else |
| 504 | | { |
| 505 | | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 506 | | } |
| 507 | | |
| 508 | | // show window |
| 509 | | |
| 510 | | SDL_ShowWindow(window().m_sdl_window); |
| 511 | | //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen); |
| 512 | | SDL_RaiseWindow(window().m_sdl_window); |
| 513 | | |
| 514 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 515 | | |
| 516 | 428 | // create renderer |
| 517 | 429 | |
| 518 | 430 | /* set hints ... */ |
| r243363 | r243364 | |
| 555 | 467 | |
| 556 | 468 | setup_texture(width, height); |
| 557 | 469 | #else |
| 558 | | m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 559 | | |
| 560 | | if (this->check_flag(FLAG_NEEDS_DOUBLEBUF)) |
| 561 | | m_extra_flags |= SDL_DOUBLEBUF; |
| 562 | | if (this->check_flag(FLAG_NEEDS_ASYNCBLIT)) |
| 563 | | m_extra_flags |= SDL_ASYNCBLIT; |
| 564 | | |
| 565 | | if (this->check_flag(FLAG_NEEDS_OPENGL)) |
| 566 | | { |
| 567 | | m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL; |
| 568 | | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 569 | | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| 570 | | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); |
| 571 | | #endif |
| 572 | | //load_gl_lib(window().machine()); |
| 573 | | } |
| 574 | | |
| 575 | | // create the SDL surface (which creates the window in windowed mode) |
| 576 | | m_sdlsurf = SDL_SetVideoMode(width, height, |
| 577 | | 0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 578 | | |
| 579 | | if (!m_sdlsurf) |
| 580 | | return 1; |
| 581 | | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(m_sdlsurf->flags & SDL_OPENGL) ) |
| 582 | | { |
| 583 | | osd_printf_error("OpenGL not supported on this driver!\n"); |
| 584 | | return 1; |
| 585 | | } |
| 586 | | |
| 587 | | window().m_width = m_sdlsurf->w; |
| 588 | | window().m_height = m_sdlsurf->h; |
| 589 | | if (sm->is_yuv) |
| 590 | | yuv_overlay_init(); |
| 591 | | |
| 592 | | // set the window title |
| 593 | | SDL_WM_SetCaption(window().m_title, "SDLMAME"); |
| 594 | | |
| 595 | 470 | #endif |
| 596 | 471 | |
| 597 | 472 | m_yuv_lookup = NULL; |
| r243363 | r243364 | |
| 621 | 496 | SDL_FreeYUVOverlay(m_yuvsurf); |
| 622 | 497 | m_yuvsurf = NULL; |
| 623 | 498 | } |
| 624 | | SDL_FreeSurface(m_sdlsurf); |
| 499 | SDL_FreeSurface(window().m_sdlsurf); |
| 625 | 500 | |
| 626 | | m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 627 | | SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags); |
| 501 | window().m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 502 | SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags); |
| 628 | 503 | |
| 629 | | window().m_width = m_sdlsurf->w; |
| 630 | | window().m_height = m_sdlsurf->h; |
| 504 | window().m_width = window().m_sdlsurf->w; |
| 505 | window().m_height = window().m_sdlsurf->h; |
| 631 | 506 | |
| 632 | 507 | if (sdl_sm->is_yuv) |
| 633 | 508 | { |
| r243363 | r243364 | |
| 652 | 527 | if (window().fullscreen() && video_config.switchres) |
| 653 | 528 | { |
| 654 | 529 | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 655 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode |
| 530 | SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode); // Try to set mode |
| 656 | 531 | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 657 | 532 | } |
| 658 | 533 | |
| r243363 | r243364 | |
| 664 | 539 | m_yuvsurf = NULL; |
| 665 | 540 | } |
| 666 | 541 | |
| 667 | | if (m_sdlsurf) |
| 542 | if (window().m_sdlsurf) |
| 668 | 543 | { |
| 669 | | SDL_FreeSurface(m_sdlsurf); |
| 670 | | m_sdlsurf = NULL; |
| 544 | SDL_FreeSurface(window().m_sdlsurf); |
| 545 | window().m_sdlsurf = NULL; |
| 671 | 546 | } |
| 672 | 547 | #endif |
| 673 | 548 | // free the memory in the window |
| r243363 | r243364 | |
| 743 | 618 | // lock it if we need it |
| 744 | 619 | #if (!SDLMAME_SDL2) |
| 745 | 620 | |
| 746 | | pitch = m_sdlsurf->pitch; |
| 747 | | bpp = m_sdlsurf->format->BytesPerPixel; |
| 748 | | rmask = m_sdlsurf->format->Rmask; |
| 749 | | gmask = m_sdlsurf->format->Gmask; |
| 750 | | bmask = m_sdlsurf->format->Bmask; |
| 621 | pitch = window().m_sdlsurf->pitch; |
| 622 | bpp = window().m_sdlsurf->format->BytesPerPixel; |
| 623 | rmask = window().m_sdlsurf->format->Rmask; |
| 624 | gmask = window().m_sdlsurf->format->Gmask; |
| 625 | bmask = window().m_sdlsurf->format->Bmask; |
| 751 | 626 | // amask = sdlsurf->format->Amask; |
| 752 | 627 | |
| 753 | 628 | if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight) |
| r243363 | r243364 | |
| 759 | 634 | m_blittimer = 3; |
| 760 | 635 | } |
| 761 | 636 | |
| 762 | | if (SDL_MUSTLOCK(m_sdlsurf)) |
| 763 | | SDL_LockSurface(m_sdlsurf); |
| 637 | if (SDL_MUSTLOCK(window().m_sdlsurf)) |
| 638 | SDL_LockSurface(window().m_sdlsurf); |
| 764 | 639 | |
| 765 | 640 | // Clear if necessary |
| 766 | 641 | if (m_blittimer > 0) |
| 767 | 642 | { |
| 768 | | memset(m_sdlsurf->pixels, 0, window().m_height * m_sdlsurf->pitch); |
| 643 | memset(window().m_sdlsurf->pixels, 0, window().m_height * window().m_sdlsurf->pitch); |
| 769 | 644 | m_blittimer--; |
| 770 | 645 | } |
| 771 | 646 | |
| r243363 | r243364 | |
| 783 | 658 | #endif |
| 784 | 659 | } |
| 785 | 660 | else |
| 786 | | surfptr = (UINT8 *)m_sdlsurf->pixels; |
| 661 | surfptr = (UINT8 *)window().m_sdlsurf->pixels; |
| 787 | 662 | #else |
| 788 | 663 | //SDL_SelectRenderer(window().sdl_window); |
| 789 | 664 | |
| r243363 | r243364 | |
| 943 | 818 | |
| 944 | 819 | // unlock and flip |
| 945 | 820 | #if (!SDLMAME_SDL2) |
| 946 | | if (SDL_MUSTLOCK(m_sdlsurf)) SDL_UnlockSurface(m_sdlsurf); |
| 821 | if (SDL_MUSTLOCK(window().m_sdlsurf)) SDL_UnlockSurface(window().m_sdlsurf); |
| 947 | 822 | if (!sm->is_yuv) |
| 948 | 823 | { |
| 949 | | SDL_Flip(m_sdlsurf); |
| 824 | SDL_Flip(window().m_sdlsurf); |
| 950 | 825 | } |
| 951 | 826 | else |
| 952 | 827 | { |
trunk/src/osd/sdl/window.c
| r243363 | r243364 | |
| 1120 | 1120 | } |
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | |
| 1124 | // create the window ..... |
| 1125 | |
| 1126 | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 1127 | * to disable panning. This has to be done before every invocation of mame. |
| 1128 | * |
| 1129 | * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0 |
| 1130 | * |
| 1131 | */ |
| 1132 | osd_printf_verbose("Enter sdl_info::create\n"); |
| 1133 | |
| 1134 | #if (SDLMAME_SDL2) |
| 1135 | |
| 1136 | if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL)) |
| 1137 | { |
| 1138 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 1139 | |
| 1140 | /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to |
| 1141 | * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension. |
| 1142 | * |
| 1143 | * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 ); |
| 1144 | * |
| 1145 | */ |
| 1146 | window->m_extra_flags = SDL_WINDOW_OPENGL; |
| 1147 | } |
| 1148 | else |
| 1149 | window->m_extra_flags = 0; |
| 1150 | |
| 1151 | // create the SDL window |
| 1152 | // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS |
| 1153 | window->m_extra_flags |= (window->fullscreen() ? |
| 1154 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 1155 | |
| 1156 | #if defined(SDLMAME_WIN32) |
| 1157 | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 1158 | #endif |
| 1159 | // create the SDL window |
| 1160 | window->m_sdl_window = SDL_CreateWindow(window->m_title, |
| 1161 | window->monitor()->position_size().x, window->monitor()->position_size().y, |
| 1162 | tempwidth, tempheight, window->m_extra_flags); |
| 1163 | //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 1164 | // width, height, m_extra_flags); |
| 1165 | |
| 1166 | if ( window->m_sdl_window == NULL ) |
| 1167 | { |
| 1168 | if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL)) |
| 1169 | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 1170 | else |
| 1171 | osd_printf_error("Window creation failed: %s\n", SDL_GetError()); |
| 1172 | return (void *) &result[1]; |
| 1173 | } |
| 1174 | |
| 1175 | if (window->fullscreen() && video_config.switchres) |
| 1176 | { |
| 1177 | SDL_DisplayMode mode; |
| 1178 | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 1179 | SDL_GetWindowDisplayMode(window->m_sdl_window, &mode); |
| 1180 | window->m_original_mode = mode; |
| 1181 | mode.w = tempwidth; |
| 1182 | mode.h = tempheight; |
| 1183 | if (window->m_refresh) |
| 1184 | mode.refresh_rate = window->m_refresh; |
| 1185 | |
| 1186 | SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode |
| 1187 | #ifndef SDLMAME_WIN32 |
| 1188 | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 1189 | * is in place after the mode switch - which will most likely be the case |
| 1190 | * This is a hack to work around a deficiency in SDL2 |
| 1191 | */ |
| 1192 | SDL_WarpMouseInWindow(window->m_sdl_window, 1, 1); |
| 1193 | #endif |
| 1194 | } |
| 1195 | else |
| 1196 | { |
| 1197 | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 1198 | } |
| 1199 | |
| 1200 | // show window |
| 1201 | |
| 1202 | SDL_ShowWindow(window->m_sdl_window); |
| 1203 | //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen); |
| 1204 | SDL_RaiseWindow(window->m_sdl_window); |
| 1205 | |
| 1206 | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 1207 | |
| 1208 | #else |
| 1209 | window->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| 1210 | |
| 1211 | if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_DOUBLEBUF)) |
| 1212 | window->m_extra_flags |= SDL_DOUBLEBUF; |
| 1213 | if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_ASYNCBLIT)) |
| 1214 | window->m_extra_flags |= SDL_ASYNCBLIT; |
| 1215 | |
| 1216 | if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL)) |
| 1217 | { |
| 1218 | window->m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL; |
| 1219 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 1220 | #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN)) |
| 1221 | SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); |
| 1222 | #endif |
| 1223 | //load_gl_lib(window->machine()); |
| 1224 | } |
| 1225 | |
| 1226 | // create the SDL surface (which creates the window in windowed mode) |
| 1227 | window->m_sdlsurf = SDL_SetVideoMode(tempwidth, tempheight, |
| 1228 | 0, SDL_SWSURFACE | SDL_ANYFORMAT | window->m_extra_flags); |
| 1229 | |
| 1230 | if (!window->m_sdlsurf) |
| 1231 | return (void *) &result[1]; |
| 1232 | if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(window->m_sdlsurf->flags & SDL_OPENGL) ) |
| 1233 | { |
| 1234 | osd_printf_error("OpenGL not supported on this driver!\n"); |
| 1235 | return (void *) &result[1]; |
| 1236 | } |
| 1237 | |
| 1238 | window->m_width = window->m_sdlsurf->w; |
| 1239 | window->m_height = window->m_sdlsurf->h; |
| 1240 | |
| 1241 | window->m_screen_width = 0; |
| 1242 | window->m_screen_height = 0; |
| 1243 | |
| 1244 | // set the window title |
| 1245 | SDL_WM_SetCaption(window->m_title, "SDLMAME"); |
| 1246 | #endif |
| 1247 | |
| 1123 | 1248 | // initialize the drawing backend |
| 1124 | | if (window->renderer().create(tempwidth, tempheight)) |
| 1249 | if (window->renderer().create(window->m_width, window->m_height)) |
| 1125 | 1250 | return (void *) &result[1]; |
| 1126 | 1251 | |
| 1127 | 1252 | // Make sure we have a consistent state |