trunk/src/osd/sdl/draw13.c
| r243366 | r243367 | |
| 118 | 118 | |
| 119 | 119 | private: |
| 120 | 120 | Uint32 m_sdl_access; |
| 121 | | SDL_Renderer * m_renderer; |
| 121 | SDL_Renderer * m_sdl_renderer; |
| 122 | 122 | render_texinfo m_texinfo; // copy of the texture info |
| 123 | 123 | HashT m_hash; // hash value for the texture (must be >= pointer size) |
| 124 | 124 | UINT32 m_flags; // rendering flags |
| r243366 | r243367 | |
| 143 | 143 | { |
| 144 | 144 | public: |
| 145 | 145 | sdl_info13(sdl_window_info *w) |
| 146 | | : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_renderer(NULL), |
| 146 | : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_sdl_renderer(NULL), |
| 147 | 147 | m_last_hofs(0), m_last_vofs(0), |
| 148 | 148 | m_resize_pending(0), m_resize_width(0), m_resize_height(0), |
| 149 | 149 | m_last_blit_time(0), m_last_blit_pixels(0) |
| r243366 | r243367 | |
| 171 | 171 | SDL_Surface *m_sdlsurf; |
| 172 | 172 | #endif |
| 173 | 173 | |
| 174 | | SDL_Renderer * m_renderer; |
| 174 | SDL_Renderer * m_sdl_renderer; |
| 175 | 175 | simple_list<texture_info> m_texlist; // list of active textures |
| 176 | 176 | |
| 177 | 177 | float m_last_hofs; |
| r243366 | r243367 | |
| 389 | 389 | |
| 390 | 390 | SDL_SetTextureBlendMode(m_texture_id, m_sdl_blendmode); |
| 391 | 391 | set_coloralphamode(m_texture_id, &prim->color); |
| 392 | | SDL_RenderCopy(m_renderer, m_texture_id, NULL, &target_rect); |
| 392 | SDL_RenderCopy(m_sdl_renderer, m_texture_id, NULL, &target_rect); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | void sdl_info13::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y) |
| r243366 | r243367 | |
| 423 | 423 | UINT32 sb = (UINT32)(255.0f * prim->color.b); |
| 424 | 424 | UINT32 sa = (UINT32)(255.0f * prim->color.a); |
| 425 | 425 | |
| 426 | | SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); |
| 427 | | SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa); |
| 428 | | SDL_RenderFillRect(m_renderer, &target_rect); |
| 426 | SDL_SetRenderDrawBlendMode(m_sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); |
| 427 | SDL_SetRenderDrawColor(m_sdl_renderer, sr, sg, sb, sa); |
| 428 | SDL_RenderFillRect(m_sdl_renderer, &target_rect); |
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | |
| r243366 | r243367 | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | if (video_config.waitvsync) |
| 598 | | m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); |
| 598 | m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); |
| 599 | 599 | else |
| 600 | | m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED); |
| 600 | m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_ACCELERATED); |
| 601 | 601 | |
| 602 | | if (!m_renderer) |
| 602 | if (!m_sdl_renderer) |
| 603 | 603 | { |
| 604 | 604 | fatalerror("Error on creating renderer: %s\n", SDL_GetError()); |
| 605 | 605 | } |
| r243366 | r243367 | |
| 608 | 608 | |
| 609 | 609 | m_blittimer = 3; |
| 610 | 610 | |
| 611 | | SDL_RenderPresent(m_renderer); |
| 611 | SDL_RenderPresent(m_sdl_renderer); |
| 612 | 612 | osd_printf_verbose("Leave sdl_info13::create\n"); |
| 613 | 613 | |
| 614 | 614 | #else |
| r243366 | r243367 | |
| 623 | 623 | |
| 624 | 624 | void sdl_info13::resize(int width, int height) |
| 625 | 625 | { |
| 626 | | m_resize_pending = 1; |
| 627 | | m_resize_height = height; |
| 628 | | m_resize_width = width; |
| 629 | | |
| 630 | | window().m_width = width; |
| 631 | | window().m_height = height; |
| 632 | | |
| 626 | SDL_RenderSetViewport(m_sdl_renderer, NULL); |
| 633 | 627 | m_blittimer = 3; |
| 634 | | |
| 635 | 628 | } |
| 636 | 629 | |
| 637 | 630 | |
| r243366 | r243367 | |
| 641 | 634 | |
| 642 | 635 | void sdl_info13::destroy() |
| 643 | 636 | { |
| 644 | | |
| 645 | | // free the memory in the window |
| 646 | | |
| 647 | 637 | destroy_all_textures(); |
| 648 | | |
| 649 | | #if (SDLMAME_SDL2) |
| 650 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 651 | | SDL_GL_DeleteContext(m_gl_context_id); |
| 652 | | if (window().fullscreen() && video_config.switchres) |
| 653 | | { |
| 654 | | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 655 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode); // Try to set mode |
| 656 | | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 657 | | } |
| 658 | | |
| 659 | | SDL_DestroyWindow(window().m_sdl_window); |
| 660 | | #else |
| 661 | | if (m_sdlsurf) |
| 662 | | { |
| 663 | | SDL_FreeSurface(m_sdlsurf); |
| 664 | | m_sdlsurf = NULL; |
| 665 | | } |
| 666 | | #endif |
| 667 | 638 | } |
| 668 | 639 | |
| 669 | 640 | //============================================================ |
| r243366 | r243367 | |
| 685 | 656 | |
| 686 | 657 | *xt = x - m_last_hofs; |
| 687 | 658 | *yt = y - m_last_vofs; |
| 688 | | if (*xt<0 || *xt >= window().m_blitwidth) |
| 659 | if (*xt<0 || *xt >= window().blitwidth()) |
| 689 | 660 | return 0; |
| 690 | | if (*yt<0 || *yt >= window().m_blitheight) |
| 661 | if (*yt<0 || *yt >= window().blitheight()) |
| 691 | 662 | return 0; |
| 692 | 663 | return 1; |
| 693 | 664 | } |
| r243366 | r243367 | |
| 724 | 695 | return 0; |
| 725 | 696 | } |
| 726 | 697 | |
| 698 | #if 0 |
| 727 | 699 | if (m_resize_pending) |
| 728 | 700 | { |
| 729 | 701 | SDL_SetWindowSize(window().m_sdl_window, m_resize_width, m_resize_height); |
| 730 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 702 | SDL_GetWindowSize(window().m_sdl_window, &window().width(), &window().height()); |
| 731 | 703 | m_resize_pending = 0; |
| 732 | | SDL_RenderSetViewport(m_renderer, NULL); |
| 704 | SDL_RenderSetViewport(m_sdl_renderer, NULL); |
| 733 | 705 | //sdlvideo_monitor_refresh(window().monitor()); |
| 734 | 706 | |
| 735 | 707 | } |
| 736 | | |
| 708 | #endif |
| 737 | 709 | //SDL_SelectRenderer(window().sdl_window); |
| 738 | 710 | |
| 739 | 711 | if (m_blittimer > 0) |
| 740 | 712 | { |
| 741 | 713 | /* SDL Underlays need alpha = 0 ! */ |
| 742 | | SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_NONE); |
| 714 | SDL_SetRenderDrawBlendMode(m_sdl_renderer, SDL_BLENDMODE_NONE); |
| 743 | 715 | //SDL_SetRenderDrawColor(0,0,0,255); |
| 744 | | SDL_SetRenderDrawColor(m_renderer, 0,0,0,0); |
| 745 | | SDL_RenderFillRect(m_renderer, NULL); |
| 716 | SDL_SetRenderDrawColor(m_sdl_renderer, 0,0,0,0); |
| 717 | SDL_RenderFillRect(m_sdl_renderer, NULL); |
| 746 | 718 | m_blittimer--; |
| 747 | 719 | } |
| 748 | 720 | |
| r243366 | r243367 | |
| 760 | 732 | } |
| 761 | 733 | else |
| 762 | 734 | { |
| 763 | | ch = window().m_height; |
| 764 | | cw = window().m_width; |
| 735 | ch = window().height(); |
| 736 | cw = window().width(); |
| 765 | 737 | } |
| 766 | 738 | |
| 767 | 739 | if (video_config.centerv) |
| 768 | 740 | { |
| 769 | | vofs = (ch - window().m_blitheight) / 2.0f; |
| 741 | vofs = (ch - window().blitheight()) / 2.0f; |
| 770 | 742 | } |
| 771 | 743 | if (video_config.centerh) |
| 772 | 744 | { |
| 773 | | hofs = (cw - window().m_blitwidth) / 2.0f; |
| 745 | hofs = (cw - window().blitwidth()) / 2.0f; |
| 774 | 746 | } |
| 775 | 747 | } |
| 776 | 748 | |
| r243366 | r243367 | |
| 792 | 764 | sb = (int)(255.0f * prim->color.b); |
| 793 | 765 | sa = (int)(255.0f * prim->color.a); |
| 794 | 766 | |
| 795 | | SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); |
| 796 | | SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa); |
| 797 | | SDL_RenderDrawLine(m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs, |
| 767 | SDL_SetRenderDrawBlendMode(m_sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); |
| 768 | SDL_SetRenderDrawColor(m_sdl_renderer, sr, sg, sb, sa); |
| 769 | SDL_RenderDrawLine(m_sdl_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs, |
| 798 | 770 | prim->bounds.x1 + hofs, prim->bounds.y1 + vofs); |
| 799 | 771 | break; |
| 800 | 772 | case render_primitive::QUAD: |
| r243366 | r243367 | |
| 814 | 786 | |
| 815 | 787 | m_last_blit_pixels = blit_pixels; |
| 816 | 788 | m_last_blit_time = -osd_ticks(); |
| 817 | | SDL_RenderPresent(m_renderer); |
| 789 | SDL_RenderPresent(m_sdl_renderer); |
| 818 | 790 | m_last_blit_time += osd_ticks(); |
| 819 | 791 | |
| 820 | 792 | return 0; |
| r243366 | r243367 | |
| 840 | 812 | if ((m_is_rotated == bi->blitter->m_is_rot) |
| 841 | 813 | && (m_sdl_blendmode == bi->bm_mask)) |
| 842 | 814 | { |
| 843 | | if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| 815 | if (RendererSupportsFormat(m_sdl_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| 844 | 816 | { |
| 845 | 817 | int perf = bi->perf; |
| 846 | 818 | if (perf == 0) |
| r243366 | r243367 | |
| 860 | 832 | { |
| 861 | 833 | if ((m_is_rotated == bi->blitter->m_is_rot) |
| 862 | 834 | && (m_sdl_blendmode == bi->bm_mask)) |
| 863 | | if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| 835 | if (RendererSupportsFormat(m_sdl_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| 864 | 836 | return bi; |
| 865 | 837 | } |
| 866 | 838 | //FIXME: crash implement a -do nothing handler */ |
| r243366 | r243367 | |
| 898 | 870 | texture_info::texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, UINT32 flags) |
| 899 | 871 | { |
| 900 | 872 | // fill in the core data |
| 901 | | m_renderer = renderer; |
| 873 | m_sdl_renderer = renderer; |
| 902 | 874 | m_hash = texture_compute_hash(texsource, flags); |
| 903 | 875 | m_flags = flags; |
| 904 | 876 | m_texinfo = texsource; |
| r243366 | r243367 | |
| 947 | 919 | |
| 948 | 920 | m_copyinfo = compute_size_type(); |
| 949 | 921 | |
| 950 | | m_texture_id = SDL_CreateTexture(m_renderer, m_copyinfo->dst_fmt, m_sdl_access, |
| 922 | m_texture_id = SDL_CreateTexture(m_sdl_renderer, m_copyinfo->dst_fmt, m_sdl_access, |
| 951 | 923 | m_setup.rotwidth, m_setup.rotheight); |
| 952 | 924 | |
| 953 | 925 | if (!m_texture_id) |
| r243366 | r243367 | |
| 1120 | 1092 | // if we didn't find one, create a new texture |
| 1121 | 1093 | if (texture == NULL && prim.texture.base != NULL) |
| 1122 | 1094 | { |
| 1123 | | texture = global_alloc(texture_info(m_renderer, prim.texture, setup, prim.flags)); |
| 1095 | texture = global_alloc(texture_info(m_sdl_renderer, prim.texture, setup, prim.flags)); |
| 1124 | 1096 | /* add us to the texture list */ |
| 1125 | 1097 | m_texlist.prepend(*texture); |
| 1126 | 1098 | |
trunk/src/osd/sdl/drawbgfx.c
| r243366 | r243367 | |
| 76 | 76 | sdl_info_bgfx(sdl_window_info *w) |
| 77 | 77 | : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_renderer(NULL), |
| 78 | 78 | m_last_hofs(0), m_last_vofs(0), |
| 79 | | m_resize_pending(0), m_resize_width(0), m_resize_height(0), |
| 80 | 79 | m_last_blit_time(0), m_last_blit_pixels(0) |
| 81 | 80 | {} |
| 82 | 81 | |
| r243366 | r243367 | |
| 101 | 100 | float m_last_hofs; |
| 102 | 101 | float m_last_vofs; |
| 103 | 102 | |
| 104 | | // resize information |
| 105 | | |
| 106 | | UINT8 m_resize_pending; |
| 107 | | UINT32 m_resize_width; |
| 108 | | UINT32 m_resize_height; |
| 109 | | |
| 110 | 103 | // Stats |
| 111 | 104 | INT64 m_last_blit_time; |
| 112 | 105 | INT64 m_last_blit_pixels; |
| r243366 | r243367 | |
| 144 | 137 | |
| 145 | 138 | int sdl_info_bgfx::create(int width, int height) |
| 146 | 139 | { |
| 147 | | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 148 | | * to disable panning. This has to be done before every invocation of mame. |
| 149 | | * |
| 150 | | * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0 |
| 151 | | * |
| 152 | | */ |
| 153 | | |
| 154 | | osd_printf_verbose("Enter drawsdl2_window_create\n"); |
| 155 | | |
| 156 | | UINT32 extra_flags = (window().fullscreen() ? |
| 157 | | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 158 | | |
| 159 | | #if defined(SDLMAME_WIN32) |
| 160 | | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 161 | | #endif |
| 162 | | // create the SDL window |
| 163 | | window().m_sdl_window = SDL_CreateWindow(window().m_title, |
| 164 | | window().monitor()->position_size().x, window().monitor()->position_size().y, |
| 165 | | width, height, extra_flags); |
| 166 | | |
| 167 | | if (window().fullscreen() && video_config.switchres) |
| 168 | | { |
| 169 | | SDL_DisplayMode mode; |
| 170 | | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 171 | | SDL_GetWindowDisplayMode(window().m_sdl_window, &mode); |
| 172 | | m_original_mode = mode; |
| 173 | | mode.w = width; |
| 174 | | mode.h = height; |
| 175 | | if (window().m_refresh) |
| 176 | | mode.refresh_rate = window().m_refresh; |
| 177 | | |
| 178 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &mode); // Try to set mode |
| 179 | | #ifndef SDLMAME_WIN32 |
| 180 | | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 181 | | * is in place after the mode switch - which will most likely be the case |
| 182 | | * This is a hack to work around a deficiency in SDL2 |
| 183 | | */ |
| 184 | | SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1); |
| 185 | | #endif |
| 186 | | } |
| 187 | | else |
| 188 | | { |
| 189 | | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 190 | | } |
| 191 | 140 | // create renderer |
| 192 | 141 | |
| 193 | | if (video_config.waitvsync) |
| 194 | | m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); |
| 195 | | else |
| 196 | | m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED); |
| 197 | | |
| 198 | | if (!m_renderer) |
| 199 | | { |
| 200 | | fatalerror("Error on creating renderer: %s\n", SDL_GetError()); |
| 201 | | } |
| 202 | | |
| 203 | | //SDL_SelectRenderer(window().m_sdl_window); |
| 204 | | SDL_ShowWindow(window().m_sdl_window); |
| 205 | | //SDL_SetWindowFullscreen(window().window_id, window().fullscreen); |
| 206 | | SDL_RaiseWindow(window().m_sdl_window); |
| 207 | | |
| 208 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 209 | | |
| 210 | 142 | m_blittimer = 3; |
| 211 | 143 | |
| 212 | | SDL_RenderPresent(m_renderer); |
| 213 | | |
| 214 | 144 | bgfx::sdlSetWindow(window().m_sdl_window); |
| 215 | 145 | bgfx::init(); |
| 216 | | bgfx::reset(window().m_width, window().m_height, BGFX_RESET_VSYNC); |
| 146 | bgfx::reset(window().width(), window().height(), BGFX_RESET_VSYNC); |
| 217 | 147 | |
| 218 | 148 | // Enable debug text. |
| 219 | 149 | bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT); |
| r243366 | r243367 | |
| 227 | 157 | |
| 228 | 158 | void sdl_info_bgfx::resize(int width, int height) |
| 229 | 159 | { |
| 230 | | m_resize_pending = 1; |
| 231 | | m_resize_height = height; |
| 232 | | m_resize_width = width; |
| 233 | | |
| 234 | | window().m_width = width; |
| 235 | | window().m_height = height; |
| 236 | | |
| 237 | 160 | m_blittimer = 3; |
| 238 | 161 | } |
| 239 | 162 | |
| r243366 | r243367 | |
| 245 | 168 | { |
| 246 | 169 | *xt = x - m_last_hofs; |
| 247 | 170 | *yt = y - m_last_vofs; |
| 248 | | if (*xt<0 || *xt >= window().m_blitwidth) |
| 171 | if (*xt<0 || *xt >= window().blitwidth()) |
| 249 | 172 | return 0; |
| 250 | | if (*yt<0 || *yt >= window().m_blitheight) |
| 173 | if (*yt<0 || *yt >= window().blitheight()) |
| 251 | 174 | return 0; |
| 252 | 175 | return 1; |
| 253 | 176 | } |
| r243366 | r243367 | |
| 265 | 188 | , 0 |
| 266 | 189 | ); |
| 267 | 190 | // Set view 0 default viewport. |
| 268 | | bgfx::setViewRect(0, 0, 0, window().m_blitwidth, window().m_blitheight); |
| 191 | bgfx::setViewRect(0, 0, 0, window().blitwidth(), window().blitheight()); |
| 269 | 192 | |
| 270 | 193 | // This dummy draw call is here to make sure that view 0 is cleared |
| 271 | 194 | // if no other draw calls are submitted to view 0. |
| r243366 | r243367 | |
| 298 | 221 | |
| 299 | 222 | destroy_all_textures(); |
| 300 | 223 | |
| 301 | | if (window().fullscreen() && video_config.switchres) |
| 302 | | { |
| 303 | | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 304 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode); // Try to set mode |
| 305 | | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 306 | | } |
| 307 | | |
| 308 | | SDL_DestroyWindow(window().m_sdl_window); |
| 309 | | |
| 310 | 224 | // Shutdown bgfx. |
| 311 | 225 | bgfx::shutdown(); |
| 312 | 226 | } |
trunk/src/osd/sdl/drawogl.c
| r243366 | r243367 | |
| 58 | 58 | typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum m_target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); |
| 59 | 59 | typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); |
| 60 | 60 | typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum m_target, GLuint renderbuffer); |
| 61 | | typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum m_target, GLenum internalformat, GLsizei m_width, GLsizei m_height); |
| 61 | typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum m_target, GLenum internalformat, GLsizei width, GLsizei height); |
| 62 | 62 | typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum m_target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); |
| 63 | 63 | typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); |
| 64 | 64 | #endif |
| r243366 | r243367 | |
| 165 | 165 | { |
| 166 | 166 | public: |
| 167 | 167 | texture_info() |
| 168 | | : hash(0), flags(0), rawwidth(0), rawheight(0), |
| 168 | : hash(0), flags(0), rawwidth(0), rawheight(0), |
| 169 | 169 | rawwidth_create(0), rawheight_create(0), |
| 170 | 170 | type(0), format(0), borderpix(0), xprescale(0), yprescale(0), nocopy(0), |
| 171 | 171 | texture(0), texTarget(0), texpow2(0), mpass_dest_idx(0), pbo(0), data(NULL), |
| r243366 | r243367 | |
| 223 | 223 | public: |
| 224 | 224 | sdl_info_ogl(sdl_window_info *window) |
| 225 | 225 | : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0), |
| 226 | m_screen_width(0), m_screen_height(0), |
| 226 | 227 | #if (SDLMAME_SDL2) |
| 227 | 228 | m_gl_context_id(0), |
| 228 | 229 | #else |
| r243366 | r243367 | |
| 277 | 278 | void texture_all_disable(); |
| 278 | 279 | |
| 279 | 280 | INT32 m_blittimer; |
| 281 | int m_screen_width; |
| 282 | int m_screen_height; |
| 280 | 283 | |
| 281 | 284 | #if (SDLMAME_SDL2) |
| 282 | 285 | SDL_GLContext m_gl_context_id; |
| r243366 | r243367 | |
| 712 | 715 | #if (SDLMAME_SDL2) |
| 713 | 716 | // create renderer |
| 714 | 717 | |
| 715 | | m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window); |
| 718 | m_gl_context_id = SDL_GL_CreateContext(window().sdl_window()); |
| 716 | 719 | if (!m_gl_context_id) |
| 717 | 720 | { |
| 718 | 721 | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| r243366 | r243367 | |
| 724 | 727 | #else |
| 725 | 728 | #endif |
| 726 | 729 | |
| 730 | m_screen_width = 0; |
| 731 | m_screen_height = 0; |
| 732 | |
| 727 | 733 | m_blittimer = 0; |
| 728 | 734 | m_surf_w = 0; |
| 729 | 735 | m_surf_h = 0; |
| r243366 | r243367 | |
| 755 | 761 | void sdl_info_ogl::resize(int width, int height) |
| 756 | 762 | { |
| 757 | 763 | #if (SDLMAME_SDL2) |
| 758 | | //SDL_GL_MakeCurrent(window().sdl_window, gl_context_id); |
| 759 | | SDL_SetWindowSize(window().m_sdl_window, width, height); |
| 760 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 761 | 764 | m_blittimer = 3; |
| 762 | | #else |
| 763 | | SDL_FreeSurface(window().m_sdlsurf); |
| 764 | | |
| 765 | | window().m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 766 | | SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags); |
| 767 | | |
| 768 | | window().m_width = window().m_sdlsurf->w; |
| 769 | | window().m_height = window().m_sdlsurf->h; |
| 770 | 765 | #endif |
| 771 | 766 | m_init_context = 1; |
| 772 | | |
| 773 | 767 | } |
| 774 | 768 | |
| 775 | 769 | |
| r243366 | r243367 | |
| 785 | 779 | destroy_all_textures(); |
| 786 | 780 | |
| 787 | 781 | #if (SDLMAME_SDL2) |
| 788 | | if (check_flag(FLAG_NEEDS_OPENGL)) |
| 789 | | SDL_GL_DeleteContext(m_gl_context_id); |
| 790 | | if (window().fullscreen() && video_config.switchres) |
| 791 | | { |
| 792 | | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 793 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode); // Try to set mode |
| 794 | | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 795 | | } |
| 796 | | |
| 797 | | SDL_DestroyWindow(window().m_sdl_window); |
| 798 | | #else |
| 799 | | if (window().m_sdlsurf) |
| 800 | | { |
| 801 | | SDL_FreeSurface(window().m_sdlsurf); |
| 802 | | window().m_sdlsurf = NULL; |
| 803 | | } |
| 782 | SDL_GL_DeleteContext(m_gl_context_id); |
| 804 | 783 | #endif |
| 784 | |
| 805 | 785 | } |
| 806 | 786 | |
| 807 | 787 | //============================================================ |
| r243366 | r243367 | |
| 823 | 803 | |
| 824 | 804 | *xt = x - m_last_hofs; |
| 825 | 805 | *yt = y - m_last_vofs; |
| 826 | | if (*xt<0 || *xt >= window().m_blitwidth) |
| 806 | if (*xt<0 || *xt >= window().blitwidth()) |
| 827 | 807 | return 0; |
| 828 | | if (*yt<0 || *yt >= window().m_blitheight) |
| 808 | if (*yt<0 || *yt >= window().blitheight()) |
| 829 | 809 | return 0; |
| 830 | 810 | return 1; |
| 831 | 811 | } |
| r243366 | r243367 | |
| 844 | 824 | return; |
| 845 | 825 | |
| 846 | 826 | #if (SDLMAME_SDL2) |
| 847 | | SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id); |
| 827 | SDL_GL_MakeCurrent(window().sdl_window(), m_gl_context_id); |
| 848 | 828 | #endif |
| 849 | 829 | |
| 850 | 830 | if(window().m_primlist) |
| r243366 | r243367 | |
| 1132 | 1112 | |
| 1133 | 1113 | if ( m_useglsl ) |
| 1134 | 1114 | { |
| 1135 | | if ( window().m_prescale != 1 ) |
| 1115 | if ( window().prescale() != 1 ) |
| 1136 | 1116 | { |
| 1137 | 1117 | m_useglsl = 0; |
| 1138 | 1118 | if (_once) |
| r243366 | r243367 | |
| 1242 | 1222 | } |
| 1243 | 1223 | |
| 1244 | 1224 | #if (SDLMAME_SDL2) |
| 1245 | | SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id); |
| 1225 | SDL_GL_MakeCurrent(window().sdl_window(), m_gl_context_id); |
| 1246 | 1226 | #else |
| 1247 | 1227 | if (!m_init_context) |
| 1248 | 1228 | { |
| r243366 | r243367 | |
| 1251 | 1231 | { |
| 1252 | 1232 | if (window().index() == 0) |
| 1253 | 1233 | { |
| 1254 | | if ((screen->width() != window().m_screen_width) || (screen->height() != window().m_screen_height)) |
| 1234 | if ((screen->width() != m_screen_width) || (screen->height() != m_screen_height)) |
| 1255 | 1235 | { |
| 1256 | | window().m_screen_width = screen->width(); |
| 1257 | | window().m_screen_height = screen->height(); |
| 1236 | m_screen_width = screen->width(); |
| 1237 | m_screen_height = screen->height(); |
| 1258 | 1238 | |
| 1259 | 1239 | // force all textures to be regenerated |
| 1260 | 1240 | destroy_all_textures(); |
| r243366 | r243367 | |
| 1305 | 1285 | } |
| 1306 | 1286 | |
| 1307 | 1287 | if ( !m_initialized || |
| 1308 | | window().m_width!= m_surf_w || window().m_height!= m_surf_h ) |
| 1288 | window().width()!= m_surf_w || window().height()!= m_surf_h ) |
| 1309 | 1289 | { |
| 1310 | 1290 | if ( !m_initialized ) |
| 1311 | 1291 | { |
| 1312 | 1292 | loadGLExtensions(); |
| 1313 | 1293 | } |
| 1314 | 1294 | |
| 1315 | | m_surf_w=window().m_width; |
| 1316 | | m_surf_h=window().m_height; |
| 1295 | m_surf_w=window().width(); |
| 1296 | m_surf_h=window().height(); |
| 1317 | 1297 | |
| 1318 | 1298 | // we're doing nothing 3d, so the Z-buffer is currently not interesting |
| 1319 | 1299 | glDisable(GL_DEPTH_TEST); |
| r243366 | r243367 | |
| 1354 | 1334 | // |_________| |
| 1355 | 1335 | // (0,h) (w,h) |
| 1356 | 1336 | |
| 1357 | | glViewport(0.0, 0.0, (GLsizei)window().m_width, (GLsizei)window().m_height); |
| 1337 | glViewport(0.0, 0.0, (GLsizei)window().width(), (GLsizei)window().height()); |
| 1358 | 1338 | glMatrixMode(GL_PROJECTION); |
| 1359 | 1339 | glLoadIdentity(); |
| 1360 | | glOrtho(0.0, (GLdouble)window().m_width, (GLdouble)window().m_height, 0.0, 0.0, -1.0); |
| 1340 | glOrtho(0.0, (GLdouble)window().width(), (GLdouble)window().height(), 0.0, 0.0, -1.0); |
| 1361 | 1341 | glMatrixMode(GL_MODELVIEW); |
| 1362 | 1342 | glLoadIdentity(); |
| 1363 | 1343 | |
| r243366 | r243367 | |
| 1384 | 1364 | } |
| 1385 | 1365 | else |
| 1386 | 1366 | { |
| 1387 | | ch = window().m_height; |
| 1388 | | cw = window().m_width; |
| 1367 | ch = window().height(); |
| 1368 | cw = window().width(); |
| 1389 | 1369 | } |
| 1390 | 1370 | |
| 1391 | 1371 | if (video_config.centerv) |
| 1392 | 1372 | { |
| 1393 | | vofs = (ch - window().m_blitheight) / 2.0f; |
| 1373 | vofs = (ch - window().blitheight()) / 2.0f; |
| 1394 | 1374 | } |
| 1395 | 1375 | if (video_config.centerh) |
| 1396 | 1376 | { |
| 1397 | | hofs = (cw - window().m_blitwidth) / 2.0f; |
| 1377 | hofs = (cw - window().blitwidth()) / 2.0f; |
| 1398 | 1378 | } |
| 1399 | 1379 | } |
| 1400 | 1380 | |
| r243366 | r243367 | |
| 1470 | 1450 | set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags)); |
| 1471 | 1451 | |
| 1472 | 1452 | // compute the effective width based on the direction of the line |
| 1473 | | effwidth = prim->m_width; |
| 1453 | effwidth = prim->width(); |
| 1474 | 1454 | if (effwidth < 0.5f) |
| 1475 | 1455 | effwidth = 0.5f; |
| 1476 | 1456 | |
| r243366 | r243367 | |
| 1575 | 1555 | // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions |
| 1576 | 1556 | m_texVerticex[0]=(GLfloat)0.0; |
| 1577 | 1557 | m_texVerticex[1]=(GLfloat)0.0; |
| 1578 | | m_texVerticex[2]=(GLfloat)window().m_width; |
| 1558 | m_texVerticex[2]=(GLfloat)window().width(); |
| 1579 | 1559 | m_texVerticex[3]=(GLfloat)0.0; |
| 1580 | | m_texVerticex[4]=(GLfloat)window().m_width; |
| 1581 | | m_texVerticex[5]=(GLfloat)window().m_height; |
| 1560 | m_texVerticex[4]=(GLfloat)window().width(); |
| 1561 | m_texVerticex[5]=(GLfloat)window().height(); |
| 1582 | 1562 | m_texVerticex[6]=(GLfloat)0.0; |
| 1583 | | m_texVerticex[7]=(GLfloat)window().m_height; |
| 1563 | m_texVerticex[7]=(GLfloat)window().height(); |
| 1584 | 1564 | } |
| 1585 | 1565 | |
| 1586 | 1566 | if(i>0) // first fetch already done |
| r243366 | r243367 | |
| 1626 | 1606 | #if (!SDLMAME_SDL2) |
| 1627 | 1607 | SDL_GL_SwapBuffers(); |
| 1628 | 1608 | #else |
| 1629 | | SDL_GL_SwapWindow(window().m_sdl_window); |
| 1609 | SDL_GL_SwapWindow(window().sdl_window()); |
| 1630 | 1610 | #endif |
| 1631 | 1611 | return 0; |
| 1632 | 1612 | } |
| r243366 | r243367 | |
| 1784 | 1764 | texture->xprescale--; |
| 1785 | 1765 | while (texture->yprescale > 1 && height_create * texture->yprescale > m_texture_max_height) |
| 1786 | 1766 | texture->yprescale--; |
| 1787 | | if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().m_prescale || texture->yprescale != window().m_prescale)) |
| 1788 | | osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().m_prescale, window().m_prescale, texture->xprescale, texture->yprescale); |
| 1767 | if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().prescale() || texture->yprescale != window().prescale())) |
| 1768 | osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().prescale(), window().prescale(), texture->xprescale, texture->yprescale); |
| 1789 | 1769 | |
| 1790 | 1770 | width *= texture->xprescale; |
| 1791 | 1771 | height *= texture->yprescale; |
| r243366 | r243367 | |
| 1964 | 1944 | { |
| 1965 | 1945 | int uniform_location; |
| 1966 | 1946 | int i; |
| 1967 | | int surf_w_pow2 = get_valid_pow2_value (window().m_blitwidth, texture->texpow2); |
| 1968 | | int surf_h_pow2 = get_valid_pow2_value (window().m_blitheight, texture->texpow2); |
| 1947 | int surf_w_pow2 = get_valid_pow2_value (window().blitwidth(), texture->texpow2); |
| 1948 | int surf_h_pow2 = get_valid_pow2_value (window().blitheight(), texture->texpow2); |
| 1969 | 1949 | |
| 1970 | 1950 | assert ( texture->type==TEXTURE_TYPE_SHADER ); |
| 1971 | 1951 | |
| r243366 | r243367 | |
| 2012 | 1992 | pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0])); |
| 2013 | 1993 | GL_CHECK_ERROR_NORMAL(); |
| 2014 | 1994 | |
| 2015 | | GLfloat screen_texture_sz[2] = { (GLfloat)window().m_blitwidth, (GLfloat)window().m_blitheight }; |
| 1995 | GLfloat screen_texture_sz[2] = { (GLfloat)window().blitwidth(), (GLfloat)window().blitheight() }; |
| 2016 | 1996 | uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_sz"); |
| 2017 | 1997 | pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0])); |
| 2018 | 1998 | GL_CHECK_ERROR_NORMAL(); |
| r243366 | r243367 | |
| 2068 | 2048 | } |
| 2069 | 2049 | |
| 2070 | 2050 | osd_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n", |
| 2071 | | window().m_width, window().m_height, surf_w_pow2, surf_h_pow2); |
| 2051 | window().width(), window().height(), surf_w_pow2, surf_h_pow2); |
| 2072 | 2052 | } |
| 2073 | 2053 | |
| 2074 | 2054 | // GL_TEXTURE0 |
| r243366 | r243367 | |
| 2147 | 2127 | texture->texinfo.seqid = -1; // force set data |
| 2148 | 2128 | if (PRIMFLAG_GET_SCREENTEX(flags)) |
| 2149 | 2129 | { |
| 2150 | | texture->xprescale = window().m_prescale; |
| 2151 | | texture->yprescale = window().m_prescale; |
| 2130 | texture->xprescale = window().prescale(); |
| 2131 | texture->yprescale = window().prescale(); |
| 2152 | 2132 | } |
| 2153 | 2133 | else |
| 2154 | 2134 | { |
| r243366 | r243367 | |
| 2778 | 2758 | } |
| 2779 | 2759 | else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>m_glsl_program_mb2sc ) |
| 2780 | 2760 | { |
| 2781 | | int surf_w_pow2 = get_valid_pow2_value (window().m_width, texture->texpow2); |
| 2782 | | int surf_h_pow2 = get_valid_pow2_value (window().m_height, texture->texpow2); |
| 2761 | int surf_w_pow2 = get_valid_pow2_value (window().width(), texture->texpow2); |
| 2762 | int surf_h_pow2 = get_valid_pow2_value (window().height(), texture->texpow2); |
| 2783 | 2763 | |
| 2784 | | ustop = (float)(window().m_width) / (float)surf_w_pow2; |
| 2785 | | vstop = (float)(window().m_height) / (float)surf_h_pow2; |
| 2764 | ustop = (float)(window().width()) / (float)surf_w_pow2; |
| 2765 | vstop = (float)(window().height()) / (float)surf_h_pow2; |
| 2786 | 2766 | } |
| 2787 | 2767 | else |
| 2788 | 2768 | { |
trunk/src/osd/sdl/drawsdl.c
| r243366 | r243367 | |
| 52 | 52 | |
| 53 | 53 | sdl_info(sdl_window_info *w, int extra_flags) |
| 54 | 54 | : osd_renderer(w, extra_flags), |
| 55 | | m_blittimer(0), |
| 56 | | |
| 57 | 55 | #if (SDLMAME_SDL2) |
| 58 | 56 | m_sdl_renderer(NULL), |
| 59 | 57 | m_texture_id(NULL), |
| r243366 | r243367 | |
| 216 | 214 | |
| 217 | 215 | static osd_renderer *drawsdl_create(sdl_window_info *window) |
| 218 | 216 | { |
| 219 | | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 220 | | |
| 221 | 217 | // FIXME: QUALITY HINTS |
| 222 | 218 | #if (SDLMAME_SDL2) |
| 223 | 219 | return global_alloc(sdl_info(window, osd_renderer::FLAG_NONE)); |
| 224 | 220 | #else |
| 221 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 225 | 222 | return global_alloc(sdl_info(window, sm->m_extra_flags)); |
| 226 | 223 | #endif |
| 227 | 224 | } |
| r243366 | r243367 | |
| 279 | 276 | int m_hw_scale_width =0; |
| 280 | 277 | int m_hw_scale_height = 0; |
| 281 | 278 | |
| 282 | | window().m_target->compute_minimum_size(m_hw_scale_width, m_hw_scale_height); |
| 279 | window().target()->compute_minimum_size(m_hw_scale_width, m_hw_scale_height); |
| 283 | 280 | if (video_config.prescale) |
| 284 | 281 | { |
| 285 | 282 | m_hw_scale_width *= video_config.prescale; |
| r243366 | r243367 | |
| 315 | 312 | const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; |
| 316 | 313 | int minimum_width, minimum_height; |
| 317 | 314 | |
| 318 | | window().m_target->compute_minimum_size(minimum_width, minimum_height); |
| 315 | window().target()->compute_minimum_size(minimum_width, minimum_height); |
| 319 | 316 | |
| 320 | 317 | if (video_config.prescale) |
| 321 | 318 | { |
| r243366 | r243367 | |
| 339 | 336 | m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); |
| 340 | 337 | |
| 341 | 338 | m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, |
| 342 | | sdl_sm->pixel_format, window().m_sdlsurf); |
| 339 | sdl_sm->pixel_format, window().sdl_surface()); |
| 343 | 340 | |
| 344 | 341 | if ( m_yuvsurf == NULL ) { |
| 345 | 342 | osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); |
| r243366 | r243367 | |
| 421 | 418 | |
| 422 | 419 | int sdl_info::create(int width, int height) |
| 423 | 420 | { |
| 424 | | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 425 | 421 | |
| 426 | 422 | #if (SDLMAME_SDL2) |
| 423 | const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; |
| 427 | 424 | |
| 428 | 425 | // create renderer |
| 429 | 426 | |
| r243366 | r243367 | |
| 432 | 429 | |
| 433 | 430 | |
| 434 | 431 | if (video_config.waitvsync) |
| 435 | | m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); |
| 432 | m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); |
| 436 | 433 | else |
| 437 | | m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED); |
| 434 | m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_ACCELERATED); |
| 438 | 435 | |
| 439 | 436 | if (!m_sdl_renderer) |
| 440 | 437 | { |
| r243366 | r243367 | |
| 483 | 480 | |
| 484 | 481 | void sdl_info::resize(int width, int height) |
| 485 | 482 | { |
| 486 | | #if (!SDLMAME_SDL2) |
| 487 | | const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; |
| 488 | | #endif |
| 489 | 483 | #if (SDLMAME_SDL2) |
| 490 | | SDL_SetWindowSize(window().m_sdl_window, width, height); |
| 491 | | SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height); |
| 492 | | |
| 484 | SDL_RenderSetViewport(m_sdl_renderer, NULL); |
| 493 | 485 | #else |
| 494 | | if (m_yuvsurf != NULL) |
| 486 | const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; |
| 487 | if (sdl_sm->is_yuv) |
| 495 | 488 | { |
| 496 | | SDL_FreeYUVOverlay(m_yuvsurf); |
| 497 | | m_yuvsurf = NULL; |
| 498 | | } |
| 499 | | SDL_FreeSurface(window().m_sdlsurf); |
| 500 | | |
| 501 | | window().m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 502 | | SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags); |
| 503 | | |
| 504 | | window().m_width = window().m_sdlsurf->w; |
| 505 | | window().m_height = window().m_sdlsurf->h; |
| 506 | | |
| 507 | | if (sdl_sm->is_yuv) |
| 508 | | { |
| 509 | 489 | yuv_overlay_init(); |
| 510 | 490 | } |
| 511 | | |
| 512 | 491 | #endif |
| 513 | 492 | } |
| 514 | 493 | |
| r243366 | r243367 | |
| 520 | 499 | void sdl_info::destroy() |
| 521 | 500 | { |
| 522 | 501 | |
| 523 | | #if (SDLMAME_SDL2) |
| 524 | | //SDL_SelectRenderer(window().sdl_window); |
| 525 | | SDL_DestroyTexture(m_texture_id); |
| 526 | | //SDL_DestroyRenderer(window().sdl_window); |
| 527 | | if (window().fullscreen() && video_config.switchres) |
| 528 | | { |
| 529 | | SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode |
| 530 | | SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode); // Try to set mode |
| 531 | | SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 532 | | } |
| 533 | | |
| 534 | | SDL_DestroyWindow(window().m_sdl_window); |
| 535 | | #else |
| 536 | | if (m_yuvsurf != NULL) |
| 537 | | { |
| 538 | | SDL_FreeYUVOverlay(m_yuvsurf); |
| 539 | | m_yuvsurf = NULL; |
| 540 | | } |
| 541 | | |
| 542 | | if (window().m_sdlsurf) |
| 543 | | { |
| 544 | | SDL_FreeSurface(window().m_sdlsurf); |
| 545 | | window().m_sdlsurf = NULL; |
| 546 | | } |
| 547 | | #endif |
| 548 | 502 | // free the memory in the window |
| 549 | 503 | |
| 504 | destroy_all_textures(); |
| 505 | |
| 550 | 506 | if (m_yuv_lookup != NULL) |
| 551 | 507 | { |
| 552 | 508 | global_free_array(m_yuv_lookup); |
| r243366 | r243367 | |
| 577 | 533 | { |
| 578 | 534 | *xt = x - m_last_hofs; |
| 579 | 535 | *yt = y - m_last_vofs; |
| 580 | | if (*xt<0 || *xt >= window().m_blitwidth) |
| 536 | if (*xt<0 || *xt >= window().blitwidth()) |
| 581 | 537 | return 0; |
| 582 | | if (*yt<0 || *yt >= window().m_blitheight) |
| 538 | if (*yt<0 || *yt >= window().blitheight()) |
| 583 | 539 | return 0; |
| 584 | 540 | return 1; |
| 585 | 541 | } |
| r243366 | r243367 | |
| 590 | 546 | |
| 591 | 547 | void sdl_info::destroy_all_textures() |
| 592 | 548 | { |
| 593 | | /* nothing to be done in soft mode */ |
| 549 | #if (SDLMAME_SDL2) |
| 550 | SDL_DestroyTexture(m_texture_id); |
| 551 | m_texture_id = NULL; |
| 552 | #else |
| 553 | if (m_yuvsurf != NULL) |
| 554 | { |
| 555 | SDL_FreeYUVOverlay(m_yuvsurf); |
| 556 | m_yuvsurf = NULL; |
| 557 | } |
| 558 | #endif |
| 594 | 559 | } |
| 595 | 560 | |
| 596 | 561 | |
| r243366 | r243367 | |
| 618 | 583 | // lock it if we need it |
| 619 | 584 | #if (!SDLMAME_SDL2) |
| 620 | 585 | |
| 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; |
| 586 | pitch = window().sdl_surface()->pitch; |
| 587 | bpp = window().sdl_surface()->format->BytesPerPixel; |
| 588 | rmask = window().sdl_surface()->format->Rmask; |
| 589 | gmask = window().sdl_surface()->format->Gmask; |
| 590 | bmask = window().sdl_surface()->format->Bmask; |
| 626 | 591 | // amask = sdlsurf->format->Amask; |
| 627 | 592 | |
| 628 | | if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight) |
| 593 | if (window().blitwidth() != m_old_blitwidth || window().blitheight() != m_old_blitheight) |
| 629 | 594 | { |
| 630 | 595 | if (sm->is_yuv) |
| 631 | 596 | yuv_overlay_init(); |
| 632 | | m_old_blitwidth = window().m_blitwidth; |
| 633 | | m_old_blitheight = window().m_blitheight; |
| 597 | m_old_blitwidth = window().blitwidth(); |
| 598 | m_old_blitheight = window().blitheight(); |
| 634 | 599 | m_blittimer = 3; |
| 635 | 600 | } |
| 636 | 601 | |
| 637 | | if (SDL_MUSTLOCK(window().m_sdlsurf)) |
| 638 | | SDL_LockSurface(window().m_sdlsurf); |
| 602 | if (SDL_MUSTLOCK(window().sdl_surface())) |
| 603 | SDL_LockSurface(window().sdl_surface()); |
| 639 | 604 | |
| 640 | 605 | // Clear if necessary |
| 641 | 606 | if (m_blittimer > 0) |
| 642 | 607 | { |
| 643 | | memset(window().m_sdlsurf->pixels, 0, window().m_height * window().m_sdlsurf->pitch); |
| 608 | memset(window().sdl_surface()->pixels, 0, window().height() * window().sdl_surface()->pitch); |
| 644 | 609 | m_blittimer--; |
| 645 | 610 | } |
| 646 | 611 | |
| r243366 | r243367 | |
| 658 | 623 | #endif |
| 659 | 624 | } |
| 660 | 625 | else |
| 661 | | surfptr = (UINT8 *)window().m_sdlsurf->pixels; |
| 626 | surfptr = (UINT8 *)window().sdl_surface()->pixels; |
| 662 | 627 | #else |
| 663 | 628 | //SDL_SelectRenderer(window().sdl_window); |
| 664 | 629 | |
| 665 | | if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight) |
| 630 | if (window().blitwidth() != m_old_blitwidth || window().blitheight() != m_old_blitheight) |
| 666 | 631 | { |
| 667 | | SDL_RenderSetViewport(m_sdl_renderer, NULL); |
| 632 | //SDL_RenderSetViewport(m_sdl_renderer, NULL); |
| 668 | 633 | |
| 669 | | SDL_DestroyTexture(m_texture_id); |
| 670 | | setup_texture(window().m_blitwidth, window().m_blitheight); |
| 671 | | m_old_blitwidth = window().m_blitwidth; |
| 672 | | m_old_blitheight = window().m_blitheight; |
| 634 | if (m_texture_id != NULL) |
| 635 | SDL_DestroyTexture(m_texture_id); |
| 636 | setup_texture(window().blitwidth(), window().blitheight()); |
| 637 | m_old_blitwidth = window().blitwidth(); |
| 638 | m_old_blitheight = window().blitheight(); |
| 673 | 639 | m_blittimer = 3; |
| 674 | 640 | } |
| 675 | 641 | |
| r243366 | r243367 | |
| 697 | 663 | #endif |
| 698 | 664 | // get ready to center the image |
| 699 | 665 | vofs = hofs = 0; |
| 700 | | blitwidth = window().m_blitwidth; |
| 701 | | blitheight = window().m_blitheight; |
| 666 | blitwidth = window().blitwidth(); |
| 667 | blitheight = window().blitheight(); |
| 702 | 668 | |
| 703 | 669 | // figure out what coordinate system to use for centering - in window mode it's always the |
| 704 | 670 | // SDL surface size. in fullscreen the surface covers all monitors, so center according to |
| r243366 | r243367 | |
| 710 | 676 | } |
| 711 | 677 | else |
| 712 | 678 | { |
| 713 | | ch = window().m_height; |
| 714 | | cw = window().m_width; |
| 679 | ch = window().height(); |
| 680 | cw = window().width(); |
| 715 | 681 | } |
| 716 | 682 | |
| 717 | 683 | // do not crash if the window's smaller than the blit area |
| r243366 | r243367 | |
| 721 | 687 | } |
| 722 | 688 | else if (video_config.centerv) |
| 723 | 689 | { |
| 724 | | vofs = (ch - window().m_blitheight) / 2; |
| 690 | vofs = (ch - window().blitheight()) / 2; |
| 725 | 691 | } |
| 726 | 692 | |
| 727 | 693 | if (blitwidth > cw) |
| r243366 | r243367 | |
| 730 | 696 | } |
| 731 | 697 | else if (video_config.centerh) |
| 732 | 698 | { |
| 733 | | hofs = (cw - window().m_blitwidth) / 2; |
| 699 | hofs = (cw - window().blitwidth()) / 2; |
| 734 | 700 | } |
| 735 | 701 | |
| 736 | 702 | m_last_hofs = hofs; |
| r243366 | r243367 | |
| 744 | 710 | if (!sm->is_yuv) |
| 745 | 711 | { |
| 746 | 712 | surfptr += ((vofs * pitch) + (hofs * bpp)); |
| 747 | | mamewidth = blitwidth; //m_sdlsurf->w; |
| 748 | | mameheight = blitheight; //m_sdlsurf->h; |
| 713 | mamewidth = blitwidth; //sdl_surface()->w; |
| 714 | mameheight = blitheight; //sdl_surface()->h; |
| 749 | 715 | } |
| 750 | 716 | else |
| 751 | 717 | { |
| r243366 | r243367 | |
| 770 | 736 | |
| 771 | 737 | for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next()) |
| 772 | 738 | { |
| 773 | | prim->bounds.x0 *= fw; |
| 774 | | prim->bounds.x1 *= fw; |
| 775 | | prim->bounds.y0 *= fh; |
| 776 | | prim->bounds.y1 *= fh; |
| 739 | prim->bounds.x0 = floor(fw * prim->bounds.x0 + 0.5f); |
| 740 | prim->bounds.x1 = floor(fw * prim->bounds.x1 + 0.5f); |
| 741 | prim->bounds.y0 = floor(fh * prim->bounds.y0 + 0.5f); |
| 742 | prim->bounds.y1 = floor(fh * prim->bounds.y1 + 0.5f); |
| 777 | 743 | } |
| 778 | 744 | |
| 779 | 745 | // render to it |
| r243366 | r243367 | |
| 818 | 784 | |
| 819 | 785 | // unlock and flip |
| 820 | 786 | #if (!SDLMAME_SDL2) |
| 821 | | if (SDL_MUSTLOCK(window().m_sdlsurf)) SDL_UnlockSurface(window().m_sdlsurf); |
| 787 | if (SDL_MUSTLOCK(window().sdl_surface())) SDL_UnlockSurface(window().sdl_surface()); |
| 822 | 788 | if (!sm->is_yuv) |
| 823 | 789 | { |
| 824 | | SDL_Flip(window().m_sdlsurf); |
| 790 | SDL_Flip(window().sdl_surface()); |
| 825 | 791 | } |
| 826 | 792 | else |
| 827 | 793 | { |
trunk/src/osd/sdl/input.c
| r243366 | r243367 | |
| 1547 | 1547 | for (w = sdl_window_list; w != NULL; w = w->m_next) |
| 1548 | 1548 | { |
| 1549 | 1549 | //printf("w->window_id: %d\n", w->window_id); |
| 1550 | | if (w->m_sdl_window == window) |
| 1550 | if (w->sdl_window() == window) |
| 1551 | 1551 | { |
| 1552 | 1552 | return w; |
| 1553 | 1553 | } |
| r243366 | r243367 | |
| 1760 | 1760 | devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x80; |
| 1761 | 1761 | #if (SDLMAME_SDL2) |
| 1762 | 1762 | if (event.key.keysym.sym < 0x20) |
| 1763 | | ui_input_push_char_event(machine, sdl_window_list->m_target, event.key.keysym.sym); |
| 1763 | ui_input_push_char_event(machine, sdl_window_list->target(), event.key.keysym.sym); |
| 1764 | 1764 | #else |
| 1765 | | ui_input_push_char_event(machine, sdl_window_list->m_target, (unicode_char) event.key.keysym.unicode); |
| 1765 | ui_input_push_char_event(machine, sdl_window_list->target(), (unicode_char) event.key.keysym.unicode); |
| 1766 | 1766 | #endif |
| 1767 | 1767 | break; |
| 1768 | 1768 | case SDL_KEYUP: |
| r243366 | r243367 | |
| 1864 | 1864 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.button); |
| 1865 | 1865 | if (window != NULL && window->xy_to_render_target(event.button.x,event.button.y, &cx, &cy) ) |
| 1866 | 1866 | { |
| 1867 | | ui_input_push_mouse_down_event(machine, window->m_target, cx, cy); |
| 1867 | ui_input_push_mouse_down_event(machine, window->target(), cx, cy); |
| 1868 | 1868 | // FIXME Parameter ? |
| 1869 | 1869 | if ((click-last_click < 250) |
| 1870 | 1870 | && (cx >= last_x - 4 && cx <= last_x + 4) |
| 1871 | 1871 | && (cy >= last_y - 4 && cy <= last_y + 4) ) |
| 1872 | 1872 | { |
| 1873 | 1873 | last_click = 0; |
| 1874 | | ui_input_push_mouse_double_click_event(machine, window->m_target, cx, cy); |
| 1874 | ui_input_push_mouse_double_click_event(machine, window->target(), cx, cy); |
| 1875 | 1875 | } |
| 1876 | 1876 | else |
| 1877 | 1877 | { |
| r243366 | r243367 | |
| 1898 | 1898 | |
| 1899 | 1899 | if (window != NULL && window->xy_to_render_target(event.button.x,event.button.y, &cx, &cy) ) |
| 1900 | 1900 | { |
| 1901 | | ui_input_push_mouse_up_event(machine, window->m_target, cx, cy); |
| 1901 | ui_input_push_mouse_up_event(machine, window->target(), cx, cy); |
| 1902 | 1902 | } |
| 1903 | 1903 | } |
| 1904 | 1904 | break; |
| r243366 | r243367 | |
| 1922 | 1922 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion); |
| 1923 | 1923 | |
| 1924 | 1924 | if (window != NULL && window->xy_to_render_target(event.motion.x, event.motion.y, &cx, &cy) ) |
| 1925 | | ui_input_push_mouse_move_event(machine, window->m_target, cx, cy); |
| 1925 | ui_input_push_mouse_move_event(machine, window->target(), cx, cy); |
| 1926 | 1926 | } |
| 1927 | 1927 | break; |
| 1928 | 1928 | case SDL_JOYBALLMOTION: |
| r243366 | r243367 | |
| 1937 | 1937 | if (!event.active.gain) |
| 1938 | 1938 | { |
| 1939 | 1939 | sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion); |
| 1940 | | ui_input_push_mouse_leave_event(machine, window->m_target); |
| 1940 | ui_input_push_mouse_leave_event(machine, window->target()); |
| 1941 | 1941 | } |
| 1942 | 1942 | break; |
| 1943 | 1943 | case SDL_QUIT: |
| r243366 | r243367 | |
| 1956 | 1956 | if (window != NULL ) |
| 1957 | 1957 | { |
| 1958 | 1958 | osd_uchar_from_osdchar(&result, event.text.text, 1); |
| 1959 | | ui_input_push_char_event(machine, window->m_target, result); |
| 1959 | ui_input_push_char_event(machine, window->target(), result); |
| 1960 | 1960 | } |
| 1961 | 1961 | } |
| 1962 | 1962 | break; |
| r243366 | r243367 | |
| 1973 | 1973 | machine.schedule_exit(); |
| 1974 | 1974 | break; |
| 1975 | 1975 | case SDL_WINDOWEVENT_LEAVE: |
| 1976 | | ui_input_push_mouse_leave_event(machine, window->m_target); |
| 1976 | ui_input_push_mouse_leave_event(machine, window->target()); |
| 1977 | 1977 | app_has_mouse_focus = 0; |
| 1978 | 1978 | break; |
| 1979 | 1979 | case SDL_WINDOWEVENT_MOVED: |
| r243366 | r243367 | |
| 1997 | 1997 | #endif |
| 1998 | 1998 | { |
| 1999 | 1999 | //printf("event data1,data2 %d x %d %ld\n", event.window.data1, event.window.data2, sizeof(SDL_Event)); |
| 2000 | | if (event.window.data1 != window->m_width || event.window.data2 != window->m_height) |
| 2000 | if (event.window.data1 != window->width() || event.window.data2 != window->height()) |
| 2001 | 2001 | window->window_resize(event.window.data1, event.window.data2); |
| 2002 | 2002 | } |
| 2003 | 2003 | } |
trunk/src/osd/sdl/window.c
| r243366 | r243367 | |
| 142 | 142 | static void sdlwindow_update_cursor_state(running_machine &machine, sdl_window_info *window); |
| 143 | 143 | static void sdlwindow_sync(void); |
| 144 | 144 | |
| 145 | | static void set_starting_view(running_machine &machine, int index, sdl_window_info *window, const char *defview, const char *view); |
| 146 | | |
| 147 | 145 | //============================================================ |
| 148 | 146 | // execute_async |
| 149 | 147 | //============================================================ |
| r243366 | r243367 | |
| 480 | 478 | { |
| 481 | 479 | worker_param * wp = (worker_param *) param; |
| 482 | 480 | sdl_window_info * window = wp->window(); |
| 481 | int width = wp->new_width(); |
| 482 | int height = wp->new_height(); |
| 483 | 483 | |
| 484 | 484 | ASSERT_WINDOW_THREAD(); |
| 485 | 485 | |
| 486 | 486 | window->renderer().destroy_all_textures(); |
| 487 | | window->renderer().resize(wp->new_width(), wp->new_height()); |
| 488 | 487 | |
| 489 | | window->blit_surface_size(wp->new_width(), wp->new_height()); |
| 488 | #if (SDLMAME_SDL2) |
| 489 | SDL_SetWindowSize(window->sdl_window(), width, height); |
| 490 | SDL_GetWindowSize(window->sdl_window(), &window->m_width, &window->m_height); |
| 491 | #else |
| 492 | SDL_FreeSurface(window->m_sdlsurf); |
| 490 | 493 | |
| 494 | window->m_sdlsurf = SDL_SetVideoMode(width, height, 0, |
| 495 | SDL_SWSURFACE | SDL_ANYFORMAT | window->m_extra_flags); |
| 496 | |
| 497 | window->m_width = window->m_sdlsurf->w; |
| 498 | window->m_height = window->m_sdlsurf->h; |
| 499 | #endif |
| 500 | |
| 501 | |
| 502 | window->renderer().resize(window->m_width, window->m_height); |
| 503 | |
| 504 | window->blit_surface_size(window->m_width, window->m_height); |
| 505 | |
| 491 | 506 | window->window_clear(); |
| 492 | 507 | |
| 493 | 508 | osd_free(wp); |
| r243366 | r243367 | |
| 498 | 513 | { |
| 499 | 514 | ASSERT_MAIN_THREAD(); |
| 500 | 515 | |
| 501 | | if (width == this->m_width && height == this->m_height) |
| 516 | if (width == this->width() && height == this->height()) |
| 502 | 517 | return; |
| 503 | 518 | |
| 504 | 519 | execute_async_wait(&sdlwindow_resize_wt, worker_param(this, width, height)); |
| r243366 | r243367 | |
| 554 | 569 | // If we are going fullscreen (leaving windowed) remember our windowed size |
| 555 | 570 | if (!window->fullscreen()) |
| 556 | 571 | { |
| 557 | | window->m_windowed_width = window->m_width; |
| 558 | | window->m_windowed_height = window->m_height; |
| 572 | window->m_windowed_width = window->width(); |
| 573 | window->m_windowed_height = window->height(); |
| 559 | 574 | } |
| 560 | 575 | |
| 561 | 576 | window->renderer().destroy(); |
| 577 | |
| 578 | #if (SDLMAME_SDL2) |
| 579 | if (window->fullscreen() && video_config.switchres) |
| 580 | { |
| 581 | SDL_SetWindowFullscreen(window->sdl_window(), 0); // Try to set mode |
| 582 | SDL_SetWindowDisplayMode(window->sdl_window(), &window->m_original_mode); // Try to set mode |
| 583 | SDL_SetWindowFullscreen(window->sdl_window(), SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 584 | } |
| 585 | SDL_DestroyWindow(window->sdl_window()); |
| 586 | #else |
| 587 | if (window->m_sdlsurf) |
| 588 | { |
| 589 | SDL_FreeSurface(window->m_sdlsurf); |
| 590 | window->m_sdlsurf = NULL; |
| 591 | } |
| 592 | #endif |
| 593 | |
| 594 | |
| 562 | 595 | sdlinput_release_keys(wp->machine()); |
| 563 | 596 | |
| 564 | 597 | // toggle the window mode |
| r243366 | r243367 | |
| 591 | 624 | void sdl_window_info::modify_prescale(running_machine &machine, int dir) |
| 592 | 625 | { |
| 593 | 626 | worker_param wp = worker_param(machine, this); |
| 594 | | int new_prescale = m_prescale; |
| 627 | int new_prescale = prescale(); |
| 595 | 628 | |
| 596 | | if (dir > 0 && m_prescale < 3) |
| 597 | | new_prescale = m_prescale + 1; |
| 598 | | if (dir < 0 && m_prescale > 1) |
| 599 | | new_prescale = m_prescale - 1; |
| 629 | if (dir > 0 && prescale() < 3) |
| 630 | new_prescale = prescale() + 1; |
| 631 | if (dir < 0 && prescale() > 1) |
| 632 | new_prescale = prescale() - 1; |
| 600 | 633 | |
| 601 | | if (new_prescale != m_prescale) |
| 634 | if (new_prescale != prescale()) |
| 602 | 635 | { |
| 603 | 636 | if (m_fullscreen && video_config.switchres) |
| 604 | 637 | { |
| r243366 | r243367 | |
| 614 | 647 | execute_async_wait(destroy_all_textures_wt, wp); |
| 615 | 648 | m_prescale = new_prescale; |
| 616 | 649 | } |
| 617 | | machine.ui().popup_time(1, "Prescale %d", m_prescale); |
| 650 | machine.ui().popup_time(1, "Prescale %d", prescale()); |
| 618 | 651 | } |
| 619 | 652 | } |
| 620 | 653 | |
| r243366 | r243367 | |
| 645 | 678 | if (!window->fullscreen() && !sdlinput_should_hide_mouse(machine)) |
| 646 | 679 | { |
| 647 | 680 | SDL_ShowCursor(SDL_ENABLE); |
| 648 | | if (SDL_GetWindowGrab(window->m_sdl_window )) |
| 649 | | SDL_SetWindowGrab(window->m_sdl_window, SDL_FALSE); |
| 681 | if (SDL_GetWindowGrab(window->sdl_window() )) |
| 682 | SDL_SetWindowGrab(window->sdl_window(), SDL_FALSE); |
| 650 | 683 | SDL_SetRelativeMouseMode(SDL_FALSE); |
| 651 | 684 | } |
| 652 | 685 | else |
| 653 | 686 | { |
| 654 | 687 | SDL_ShowCursor(SDL_DISABLE); |
| 655 | | if (!SDL_GetWindowGrab(window->m_sdl_window)) |
| 656 | | SDL_SetWindowGrab(window->m_sdl_window, SDL_TRUE); |
| 688 | if (!SDL_GetWindowGrab(window->sdl_window())) |
| 689 | SDL_SetWindowGrab(window->sdl_window(), SDL_TRUE); |
| 657 | 690 | SDL_SetRelativeMouseMode(SDL_TRUE); |
| 658 | 691 | } |
| 659 | 692 | SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility |
| r243366 | r243367 | |
| 706 | 739 | // (main thread) |
| 707 | 740 | //============================================================ |
| 708 | 741 | |
| 709 | | int sdlwindow_video_window_create(running_machine &machine, int index, sdl_monitor_info *monitor, const sdl_window_config *config) |
| 742 | int sdl_window_info::window_init() |
| 710 | 743 | { |
| 711 | | sdl_window_info *window; |
| 712 | 744 | worker_param *wp = (worker_param *) osd_malloc(sizeof(worker_param)); |
| 713 | 745 | int result; |
| 714 | 746 | |
| 715 | 747 | ASSERT_MAIN_THREAD(); |
| 716 | 748 | |
| 717 | | // allocate a new window object |
| 718 | | window = global_alloc(sdl_window_info(&machine, monitor, index, config)); |
| 719 | | |
| 720 | 749 | // set the initial maximized state |
| 721 | 750 | // FIXME: Does not belong here |
| 722 | | sdl_options &options = downcast<sdl_options &>(machine.options()); |
| 723 | | window->m_startmaximized = options.maximize(); |
| 751 | sdl_options &options = downcast<sdl_options &>(m_machine.options()); |
| 752 | m_startmaximized = options.maximize(); |
| 724 | 753 | |
| 725 | 754 | // add us to the list |
| 726 | | *last_window_ptr = window; |
| 727 | | last_window_ptr = &window->m_next; |
| 755 | *last_window_ptr = this; |
| 756 | last_window_ptr = &this->m_next; |
| 728 | 757 | |
| 729 | | window->set_renderer(draw.create(window)); |
| 758 | set_renderer(draw.create(this)); |
| 730 | 759 | |
| 731 | 760 | // create an event that we can use to skip blitting |
| 732 | | window->m_rendered_event = osd_event_alloc(FALSE, TRUE); |
| 761 | m_rendered_event = osd_event_alloc(FALSE, TRUE); |
| 733 | 762 | |
| 734 | 763 | // load the layout |
| 735 | | window->m_target = machine.render().target_alloc(); |
| 764 | m_target = m_machine.render().target_alloc(); |
| 736 | 765 | |
| 737 | 766 | // set the specific view |
| 738 | | set_starting_view(machine, index, window, options.view(), options.view(index)); |
| 767 | set_starting_view(m_machine, m_index, options.view(), options.view(m_index)); |
| 739 | 768 | |
| 740 | 769 | // make the window title |
| 741 | 770 | if (video_config.numscreens == 1) |
| 742 | | sprintf(window->m_title, "%s: %s [%s]", emulator_info::get_appname(), machine.system().description, machine.system().name); |
| 771 | sprintf(m_title, "%s: %s [%s]", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name); |
| 743 | 772 | else |
| 744 | | sprintf(window->m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine.system().description, machine.system().name, index); |
| 773 | sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name, m_index); |
| 745 | 774 | |
| 746 | | wp->set_window(window); |
| 775 | wp->set_window(this); |
| 747 | 776 | |
| 748 | 777 | // FIXME: pass error back in a different way |
| 749 | 778 | if (multithreading_enabled) |
| r243366 | r243367 | |
| 765 | 794 | return 0; |
| 766 | 795 | |
| 767 | 796 | error: |
| 768 | | window->video_window_destroy(machine); |
| 797 | video_window_destroy(m_machine); |
| 769 | 798 | // free the window itself |
| 770 | | global_free(window); |
| 771 | 799 | return 1; |
| 772 | 800 | } |
| 773 | 801 | |
| r243366 | r243367 | |
| 787 | 815 | // free the textures etc |
| 788 | 816 | window->renderer().destroy(); |
| 789 | 817 | |
| 818 | #if (SDLMAME_SDL2) |
| 819 | if (window->fullscreen() && video_config.switchres) |
| 820 | { |
| 821 | SDL_SetWindowFullscreen(window->sdl_window(), 0); // Try to set mode |
| 822 | SDL_SetWindowDisplayMode(window->sdl_window(), &window->m_original_mode); // Try to set mode |
| 823 | SDL_SetWindowFullscreen(window->sdl_window(), SDL_WINDOW_FULLSCREEN); // Try to set mode |
| 824 | } |
| 825 | SDL_DestroyWindow(window->sdl_window()); |
| 826 | #else |
| 827 | if (window->m_sdlsurf) |
| 828 | { |
| 829 | SDL_FreeSurface(window->m_sdlsurf); |
| 830 | window->m_sdlsurf = NULL; |
| 831 | } |
| 832 | #endif |
| 833 | |
| 790 | 834 | // release all keys ... |
| 791 | 835 | sdlinput_release_keys(wp->machine()); |
| 792 | 836 | |
| r243366 | r243367 | |
| 843 | 887 | m_target->compute_minimum_size(minimum_width, minimum_height); |
| 844 | 888 | |
| 845 | 889 | // use those as the target for now |
| 846 | | target_width = minimum_width * MAX(1, m_prescale); |
| 847 | | target_height = minimum_height * MAX(1, m_prescale); |
| 890 | target_width = minimum_width * MAX(1, prescale()); |
| 891 | target_height = minimum_height * MAX(1, prescale()); |
| 848 | 892 | |
| 849 | 893 | // if we're not stretching, allow some slop on the minimum since we can handle it |
| 850 | 894 | { |
| r243366 | r243367 | |
| 910 | 954 | m_target->compute_minimum_size(minimum_width, minimum_height); |
| 911 | 955 | |
| 912 | 956 | // use those as the target for now |
| 913 | | target_width = minimum_width * MAX(1, m_prescale); |
| 914 | | target_height = minimum_height * MAX(1, m_prescale); |
| 957 | target_width = minimum_width * MAX(1, prescale()); |
| 958 | target_height = minimum_height * MAX(1, prescale()); |
| 915 | 959 | |
| 916 | 960 | // if we're not stretching, allow some slop on the minimum since we can handle it |
| 917 | 961 | { |
| r243366 | r243367 | |
| 1003 | 1047 | |
| 1004 | 1048 | if (!this->m_fullscreen) |
| 1005 | 1049 | { |
| 1006 | | blit_surface_size(m_width, m_height); |
| 1050 | blit_surface_size(width(), height()); |
| 1007 | 1051 | //Don't resize window without user interaction; |
| 1008 | 1052 | //window_resize(blitwidth, blitheight); |
| 1009 | 1053 | } |
| r243366 | r243367 | |
| 1049 | 1093 | // (main thread) |
| 1050 | 1094 | //============================================================ |
| 1051 | 1095 | |
| 1052 | | static void set_starting_view(running_machine &machine, int index, sdl_window_info *window, const char *defview, const char *view) |
| 1096 | void sdl_window_info::set_starting_view(running_machine &machine, int index, const char *defview, const char *view) |
| 1053 | 1097 | { |
| 1054 | 1098 | int viewindex; |
| 1055 | 1099 | |
| r243366 | r243367 | |
| 1060 | 1104 | view = defview; |
| 1061 | 1105 | |
| 1062 | 1106 | // query the video system to help us pick a view |
| 1063 | | viewindex = window->m_target->configured_view(view, index, video_config.numscreens); |
| 1107 | viewindex = target()->configured_view(view, index, video_config.numscreens); |
| 1064 | 1108 | |
| 1065 | 1109 | // set the view |
| 1066 | | window->m_target->set_view(viewindex); |
| 1067 | | window->m_start_viewscreen=viewindex; |
| 1110 | target()->set_view(viewindex); |
| 1111 | m_start_viewscreen=viewindex; |
| 1068 | 1112 | } |
| 1069 | 1113 | |
| 1070 | 1114 | |
| r243366 | r243367 | |
| 1160 | 1204 | window->m_sdl_window = SDL_CreateWindow(window->m_title, |
| 1161 | 1205 | window->monitor()->position_size().x, window->monitor()->position_size().y, |
| 1162 | 1206 | tempwidth, tempheight, window->m_extra_flags); |
| 1163 | | //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 1207 | //window().sdl_window() = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 1164 | 1208 | // width, height, m_extra_flags); |
| 1165 | 1209 | |
| 1166 | 1210 | if ( window->m_sdl_window == NULL ) |
| r243366 | r243367 | |
| 1176 | 1220 | { |
| 1177 | 1221 | SDL_DisplayMode mode; |
| 1178 | 1222 | //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); |
| 1179 | | SDL_GetWindowDisplayMode(window->m_sdl_window, &mode); |
| 1223 | SDL_GetWindowDisplayMode(window->sdl_window(), &mode); |
| 1180 | 1224 | window->m_original_mode = mode; |
| 1181 | 1225 | mode.w = tempwidth; |
| 1182 | 1226 | mode.h = tempheight; |
| 1183 | 1227 | if (window->m_refresh) |
| 1184 | 1228 | mode.refresh_rate = window->m_refresh; |
| 1185 | 1229 | |
| 1186 | | SDL_SetWindowDisplayMode(window->m_sdl_window, &mode); // Try to set mode |
| 1230 | SDL_SetWindowDisplayMode(window->sdl_window(), &mode); // Try to set mode |
| 1187 | 1231 | #ifndef SDLMAME_WIN32 |
| 1188 | 1232 | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| 1189 | 1233 | * is in place after the mode switch - which will most likely be the case |
| 1190 | 1234 | * This is a hack to work around a deficiency in SDL2 |
| 1191 | 1235 | */ |
| 1192 | | SDL_WarpMouseInWindow(window->m_sdl_window, 1, 1); |
| 1236 | SDL_WarpMouseInWindow(window->sdl_window(), 1, 1); |
| 1193 | 1237 | #endif |
| 1194 | 1238 | } |
| 1195 | 1239 | else |
| 1196 | 1240 | { |
| 1197 | | //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop |
| 1241 | //SDL_SetWindowDisplayMode(window().sdl_window(), NULL); // Use desktop |
| 1198 | 1242 | } |
| 1199 | 1243 | |
| 1200 | 1244 | // show window |
| 1201 | 1245 | |
| 1202 | | SDL_ShowWindow(window->m_sdl_window); |
| 1203 | | //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen); |
| 1204 | | SDL_RaiseWindow(window->m_sdl_window); |
| 1246 | SDL_ShowWindow(window->sdl_window()); |
| 1247 | //SDL_SetWindowFullscreen(window().sdl_window(), window().fullscreen); |
| 1248 | SDL_RaiseWindow(window->sdl_window()); |
| 1205 | 1249 | |
| 1206 | | SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height); |
| 1250 | SDL_GetWindowSize(window->sdl_window(), &window->m_width, &window->m_height); |
| 1207 | 1251 | |
| 1208 | 1252 | #else |
| 1209 | 1253 | window->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); |
| r243366 | r243367 | |
| 1238 | 1282 | window->m_width = window->m_sdlsurf->w; |
| 1239 | 1283 | window->m_height = window->m_sdlsurf->h; |
| 1240 | 1284 | |
| 1241 | | window->m_screen_width = 0; |
| 1242 | | window->m_screen_height = 0; |
| 1243 | | |
| 1244 | 1285 | // set the window title |
| 1245 | 1286 | SDL_WM_SetCaption(window->m_title, "SDLMAME"); |
| 1246 | 1287 | #endif |
| 1247 | 1288 | |
| 1248 | 1289 | // initialize the drawing backend |
| 1249 | | if (window->renderer().create(window->m_width, window->m_height)) |
| 1290 | if (window->renderer().create(window->width(), window->height())) |
| 1250 | 1291 | return (void *) &result[1]; |
| 1251 | 1292 | |
| 1252 | 1293 | // Make sure we have a consistent state |
trunk/src/osd/sdl/window.h
| r243366 | r243367 | |
| 75 | 75 | class sdl_window_info |
| 76 | 76 | { |
| 77 | 77 | public: |
| 78 | | sdl_window_info(running_machine *a_machine, sdl_monitor_info *a_monitor, |
| 79 | | int index, const sdl_window_config *config) |
| 80 | | : m_next(NULL), m_minwidth(0), m_minheight(0), |
| 81 | | m_startmaximized(0), |
| 82 | | m_rendered_event(0), m_target(0), m_primlist(NULL), |
| 83 | | m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0), |
| 78 | sdl_window_info(running_machine &a_machine, int index, sdl_monitor_info *a_monitor, |
| 79 | const sdl_window_config *config) |
| 80 | : m_next(NULL), m_primlist(NULL), |
| 84 | 81 | m_start_viewscreen(0), |
| 82 | // Following three are used by input code to defer resizes |
| 85 | 83 | #if (SDLMAME_SDL2) |
| 86 | | m_sdl_window(NULL), |
| 87 | 84 | m_resize_width(0), |
| 88 | 85 | m_resize_height(0), |
| 89 | 86 | m_last_resize(0), |
| 87 | #endif |
| 88 | m_minwidth(0), m_minheight(0), |
| 89 | m_rendered_event(0), m_target(0), |
| 90 | m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0), |
| 91 | #if (SDLMAME_SDL2) |
| 92 | m_sdl_window(NULL), |
| 93 | |
| 90 | 94 | #else |
| 91 | 95 | m_sdlsurf(NULL), |
| 92 | | m_screen_width(0), m_screen_height(0), |
| 93 | 96 | #endif |
| 94 | 97 | m_machine(a_machine), m_monitor(a_monitor), m_fullscreen(0), m_index(0) |
| 95 | 98 | { |
| r243366 | r243367 | |
| 112 | 115 | global_free(m_renderer); |
| 113 | 116 | } |
| 114 | 117 | |
| 118 | int window_init(); |
| 119 | |
| 115 | 120 | void video_window_update(running_machine &machine); |
| 116 | 121 | void toggle_full_screen(running_machine &machine); |
| 117 | 122 | void modify_prescale(running_machine &machine, int dir); |
| r243366 | r243367 | |
| 122 | 127 | void get_min_bounds(int *window_width, int *window_height, int constrain); |
| 123 | 128 | void get_max_bounds(int *window_width, int *window_height, int constrain); |
| 124 | 129 | |
| 125 | | running_machine &machine() const { assert(m_machine != NULL); return *m_machine; } |
| 130 | running_machine &machine() const { return m_machine; } |
| 126 | 131 | sdl_monitor_info *monitor() const { return m_monitor; } |
| 127 | 132 | int fullscreen() const { return m_fullscreen; } |
| 128 | 133 | |
| r243366 | r243367 | |
| 130 | 135 | |
| 131 | 136 | void blit_surface_size(int window_width, int window_height); |
| 132 | 137 | void pick_best_mode(int *fswidth, int *fsheight); |
| 138 | void set_starting_view(running_machine &machine, int index, const char *defview, const char *view); |
| 139 | |
| 133 | 140 | int index() const { return m_index; } |
| 134 | 141 | |
| 135 | 142 | int xy_to_render_target(int x, int y, int *xt, int *yt); |
| 136 | 143 | |
| 144 | |
| 145 | render_target *target() { return m_target; } |
| 146 | #if (SDLMAME_SDL2) |
| 147 | SDL_Window *sdl_window() { return m_sdl_window; } |
| 148 | #else |
| 149 | SDL_Surface *sdl_surface() { return m_sdlsurf; } |
| 150 | #endif |
| 151 | int width() const { return m_width; } |
| 152 | int height() const { return m_height; } |
| 153 | |
| 154 | int blitwidth() const { return m_blitwidth; } |
| 155 | int blitheight() const { return m_blitheight; } |
| 156 | int prescale() const { return m_prescale; } |
| 157 | |
| 137 | 158 | // Pointer to next window |
| 138 | 159 | sdl_window_info * m_next; |
| 139 | 160 | |
| 161 | // FIXME: renderer should deal with this |
| 162 | render_primitive_list *m_primlist; |
| 163 | int m_start_viewscreen; |
| 164 | #if (SDLMAME_SDL2) |
| 165 | // These are used in combine resizing events ... #if SDL13_COMBINE_RESIZE |
| 166 | int m_resize_width; |
| 167 | int m_resize_height; |
| 168 | osd_ticks_t m_last_resize; |
| 169 | #endif |
| 170 | |
| 171 | private: |
| 140 | 172 | // window handle and info |
| 141 | 173 | char m_title[256]; |
| 142 | 174 | |
| r243366 | r243367 | |
| 152 | 184 | // rendering info |
| 153 | 185 | osd_event * m_rendered_event; |
| 154 | 186 | render_target * m_target; |
| 155 | | render_primitive_list *m_primlist; |
| 156 | 187 | |
| 157 | | // cache of physical m_width and m_height |
| 188 | // cache of physical width() and height() |
| 158 | 189 | int m_width; |
| 159 | 190 | int m_height; |
| 160 | 191 | |
| 161 | | // current m_blitwidth and m_height |
| 192 | // current m_blitwidth and height() |
| 162 | 193 | int m_blitwidth; |
| 163 | 194 | int m_blitheight; |
| 164 | 195 | |
| 165 | | int m_start_viewscreen; |
| 166 | 196 | |
| 167 | | // GL specific |
| 168 | 197 | int m_prescale; |
| 169 | 198 | |
| 170 | 199 | #if (SDLMAME_SDL2) |
| r243366 | r243367 | |
| 172 | 201 | SDL_Window *m_sdl_window; |
| 173 | 202 | // Original display_mode |
| 174 | 203 | SDL_DisplayMode m_original_mode; |
| 175 | | // These are used in combine resizing events ... #if SDL13_COMBINE_RESIZE |
| 176 | | int m_resize_width; |
| 177 | | int m_resize_height; |
| 178 | | osd_ticks_t m_last_resize; |
| 179 | 204 | #else |
| 180 | 205 | // SDL surface |
| 181 | 206 | SDL_Surface *m_sdlsurf; |
| 207 | #endif |
| 182 | 208 | |
| 183 | | int m_screen_width; |
| 184 | | int m_screen_height; |
| 185 | | #endif |
| 186 | 209 | int m_extra_flags; |
| 187 | 210 | |
| 188 | 211 | void set_renderer(osd_renderer *renderer) |
| r243366 | r243367 | |
| 197 | 220 | void constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment); |
| 198 | 221 | |
| 199 | 222 | // Pointer to machine |
| 200 | | running_machine * m_machine; |
| 223 | running_machine & m_machine; |
| 201 | 224 | // monitor info |
| 202 | 225 | sdl_monitor_info * m_monitor; |
| 203 | 226 | int m_fullscreen; |
| r243366 | r243367 | |
| 234 | 257 | // PROTOTYPES |
| 235 | 258 | //============================================================ |
| 236 | 259 | |
| 237 | | // creation/deletion of windows |
| 238 | | int sdlwindow_video_window_create(running_machine &machine, int index, sdl_monitor_info *monitor, const sdl_window_config *config); |
| 239 | | |
| 240 | 260 | //============================================================ |
| 241 | 261 | // PROTOTYPES - drawsdl.c |
| 242 | 262 | //============================================================ |