diff options
Diffstat (limited to 'src')
36 files changed, 459 insertions, 529 deletions
diff --git a/src/osd/modules/debugger/debugwin.cpp b/src/osd/modules/debugger/debugwin.cpp index 1f68e6989eb..78b21c27269 100644 --- a/src/osd/modules/debugger/debugwin.cpp +++ b/src/osd/modules/debugger/debugwin.cpp @@ -236,7 +236,7 @@ void debugger_windows::show_all() void debugger_windows::hide_all() { - SetForegroundWindow(win_window_list.front()->platform_window<HWND>()); + SetForegroundWindow(win_window_list->platform_window<HWND>()); for (debugwin_info &info : m_window_list) info.hide(); } diff --git a/src/osd/modules/debugger/win/debugwininfo.cpp b/src/osd/modules/debugger/win/debugwininfo.cpp index d46b5a1d79c..3b91b43e1fe 100644 --- a/src/osd/modules/debugger/win/debugwininfo.cpp +++ b/src/osd/modules/debugger/win/debugwininfo.cpp @@ -35,7 +35,7 @@ debugwin_info::debugwin_info(debugger_windows_interface &debugger, bool is_main_ register_window_class(); m_wnd = win_create_window_ex_utf8(DEBUG_WINDOW_STYLE_EX, "MAMEDebugWindow", title, DEBUG_WINDOW_STYLE, - 0, 0, 100, 100, win_window_list.front()->platform_window<HWND>(), create_standard_menubar(), GetModuleHandleUni(), this); + 0, 0, 100, 100, win_window_list->platform_window<HWND>(), create_standard_menubar(), GetModuleHandleUni(), this); if (m_wnd == nullptr) return; diff --git a/src/osd/modules/input/input_dinput.cpp b/src/osd/modules/input/input_dinput.cpp index 5aa925edefe..8b2fd3c1b96 100644 --- a/src/osd/modules/input/input_dinput.cpp +++ b/src/osd/modules/input/input_dinput.cpp @@ -564,7 +564,7 @@ public: dinput_joystick_device *devinfo; int result = 0; - if (!win_window_list.empty() && win_window_list.front()->win_has_menu()) + if (win_window_list != nullptr && win_window_list->win_has_menu()) cooperative_level = DISCL_BACKGROUND | DISCL_NONEXCLUSIVE; // allocate and link in a new device diff --git a/src/osd/modules/input/input_dinput.h b/src/osd/modules/input/input_dinput.h index f06520cb285..f339bef561e 100644 --- a/src/osd/modules/input/input_dinput.h +++ b/src/osd/modules/input/input_dinput.h @@ -103,7 +103,7 @@ public: } // set the cooperative level - result = devinfo->dinput.device->SetCooperativeLevel(win_window_list.front()->platform_window<HWND>(), cooperative_level); + result = devinfo->dinput.device->SetCooperativeLevel(win_window_list->platform_window<HWND>(), cooperative_level); if (result != DI_OK) goto error; diff --git a/src/osd/modules/input/input_rawinput.cpp b/src/osd/modules/input/input_rawinput.cpp index 7476fea24a6..20ed82cc4a1 100644 --- a/src/osd/modules/input/input_rawinput.cpp +++ b/src/osd/modules/input/input_rawinput.cpp @@ -475,7 +475,7 @@ public: registration.usUsagePage = usagepage(); registration.usUsage = usage(); registration.dwFlags = m_global_inputs_enabled ? 0x00000100 : 0; - registration.hwndTarget = win_window_list.front()->platform_window<HWND>(); + registration.hwndTarget = win_window_list->platform_window<HWND>(); // register the device register_rawinput_devices(®istration, 1, sizeof(registration)); diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp index f91d083371d..aa39160fd0d 100644 --- a/src/osd/modules/input/input_sdl.cpp +++ b/src/osd/modules/input/input_sdl.cpp @@ -115,7 +115,7 @@ public: } protected: - std::shared_ptr<sdl_window_info> focus_window() + sdl_window_info * focus_window() { return sdl_event_manager::instance().focus_window(); } @@ -144,7 +144,7 @@ public: case SDL_KEYDOWN: keyboard.state[OSD_SDL_INDEX_KEYSYM(&sdlevent.key.keysym)] = 0x80; if (sdlevent.key.keysym.sym < 0x20) - machine().ui_input().push_char_event(sdl_window_list.front()->target(), sdlevent.key.keysym.sym); + machine().ui_input().push_char_event(sdl_window_list->target(), sdlevent.key.keysym.sym); break; case SDL_KEYUP: @@ -154,7 +154,7 @@ public: case SDL_TEXTINPUT: if (*sdlevent.text.text) { - auto window = GET_FOCUS_WINDOW(&event.text); + sdl_window_info *window = GET_FOCUS_WINDOW(&event.text); //printf("Focus window is %p - wl %p\n", window, sdl_window_list); unicode_char result; if (window != nullptr) @@ -210,7 +210,7 @@ public: { int cx = -1, cy = -1; - auto window = GET_FOCUS_WINDOW(&sdlevent.motion); + sdl_window_info *window = GET_FOCUS_WINDOW(&sdlevent.motion); if (window != nullptr && window->xy_to_render_target(sdlevent.motion.x, sdlevent.motion.y, &cx, &cy)) machine().ui_input().push_mouse_move_event(window->target(), cx, cy); @@ -228,7 +228,7 @@ public: static int last_y = 0; int cx, cy; osd_ticks_t click = osd_ticks() * 1000 / osd_ticks_per_second(); - auto window = GET_FOCUS_WINDOW(&sdlevent.button); + sdl_window_info *window = GET_FOCUS_WINDOW(&sdlevent.button); if (window != nullptr && window->xy_to_render_target(sdlevent.button.x, sdlevent.button.y, &cx, &cy)) { machine().ui_input().push_mouse_down_event(window->target(), cx, cy); @@ -252,7 +252,7 @@ public: else if (sdlevent.button.button == 3) { int cx, cy; - auto window = GET_FOCUS_WINDOW(&sdlevent.button); + sdl_window_info *window = GET_FOCUS_WINDOW(&sdlevent.button); if (window != nullptr && window->xy_to_render_target(sdlevent.button.x, sdlevent.button.y, &cx, &cy)) { @@ -268,7 +268,7 @@ public: if (sdlevent.button.button == 1) { int cx, cy; - auto window = GET_FOCUS_WINDOW(&sdlevent.button); + sdl_window_info *window = GET_FOCUS_WINDOW(&sdlevent.button); if (window != nullptr && window->xy_to_render_target(sdlevent.button.x, sdlevent.button.y, &cx, &cy)) { @@ -278,7 +278,7 @@ public: else if (sdlevent.button.button == 3) { int cx, cy; - auto window = GET_FOCUS_WINDOW(&sdlevent.button); + sdl_window_info *window = GET_FOCUS_WINDOW(&sdlevent.button); if (window != nullptr && window->xy_to_render_target(sdlevent.button.x, sdlevent.button.y, &cx, &cy)) { @@ -288,7 +288,7 @@ public: break; case SDL_MOUSEWHEEL: - auto window = GET_FOCUS_WINDOW(&sdlevent.wheel); + sdl_window_info *window = GET_FOCUS_WINDOW(&sdlevent.wheel); if (window != nullptr) machine().ui_input().push_mouse_wheel_event(window->target(), 0, 0, sdlevent.wheel.y, 3); break; diff --git a/src/osd/modules/input/input_sdlcommon.cpp b/src/osd/modules/input/input_sdlcommon.cpp index 82c470534b2..5cc6c6f901d 100644 --- a/src/osd/modules/input/input_sdlcommon.cpp +++ b/src/osd/modules/input/input_sdlcommon.cpp @@ -35,11 +35,12 @@ #define GET_WINDOW(ev) window_from_id((ev)->windowID) //#define GET_WINDOW(ev) ((ev)->windowID) -static inline std::shared_ptr<sdl_window_info> window_from_id(Uint32 windowID) +static inline sdl_window_info * window_from_id(Uint32 windowID) { + sdl_window_info *w; SDL_Window *window = SDL_GetWindowFromID(windowID); - for (auto w : sdl_window_list) + for (w = sdl_window_list; w != NULL; w = w->m_next) { //printf("w->window_id: %d\n", w->window_id); if (w->platform_window<SDL_Window*>() == window) @@ -71,7 +72,7 @@ void sdl_event_manager::process_events(running_machine &machine) void sdl_event_manager::process_window_event(running_machine &machine, SDL_Event &sdlevent) { - std::shared_ptr<sdl_window_info> window = GET_WINDOW(&sdlevent.window); + sdl_window_info *window = GET_WINDOW(&sdlevent.window); if (window == nullptr) return; @@ -272,9 +273,7 @@ void sdl_osd_interface::poll_inputs(running_machine &machine) void sdl_osd_interface::release_keys() { - auto keybd = dynamic_cast<input_module_base*>(m_keyboard_input); - if (keybd != nullptr) - keybd->devicelist()->reset_devices(); + downcast<input_module_base*>(m_keyboard_input)->devicelist()->reset_devices(); } bool sdl_osd_interface::should_hide_mouse() diff --git a/src/osd/modules/input/input_sdlcommon.h b/src/osd/modules/input/input_sdlcommon.h index abdc4ddf4ed..eb2563b9702 100644 --- a/src/osd/modules/input/input_sdlcommon.h +++ b/src/osd/modules/input/input_sdlcommon.h @@ -119,7 +119,7 @@ class sdl_event_manager : public event_manager_t<sdl_event_subscriber> private: bool m_mouse_over_window; bool m_has_focus; - std::shared_ptr<sdl_window_info> m_focus_window; + sdl_window_info * m_focus_window; sdl_event_manager() : m_mouse_over_window(true), @@ -130,8 +130,8 @@ private: public: bool mouse_over_window() const { return m_mouse_over_window; } - bool has_focus() const { return m_focus_window != nullptr; } - std::shared_ptr<sdl_window_info> focus_window() const { return m_focus_window; } + bool has_focus() const { return m_focus_window; } + sdl_window_info * focus_window() { return m_focus_window; } static sdl_event_manager& instance() { diff --git a/src/osd/modules/input/input_win32.cpp b/src/osd/modules/input/input_win32.cpp index d02c73c987a..bafa3a21bd3 100644 --- a/src/osd/modules/input/input_win32.cpp +++ b/src/osd/modules/input/input_win32.cpp @@ -152,7 +152,7 @@ public: mouse.lY = (cursor_info.ptScreenPos.y - win32_mouse.last_point.y) * INPUT_RELATIVE_PER_PIXEL; RECT window_pos = {0}; - GetWindowRect(win_window_list.front()->platform_window<HWND>(), &window_pos); + GetWindowRect(win_window_list->platform_window<HWND>(), &window_pos); // We reset the cursor position to the middle of the window each frame win32_mouse.last_point.x = window_pos.left + (window_pos.right - window_pos.left) / 2; @@ -269,13 +269,13 @@ public: // get the cursor position and transform into final results GetCursorPos(&mousepos); - if (!win_window_list.empty()) + if (win_window_list != NULL) { RECT client_rect; // get the position relative to the window - GetClientRect(win_window_list.front()->platform_window<HWND>(), &client_rect); - ScreenToClient(win_window_list.front()->platform_window<HWND>(), &mousepos); + GetClientRect(win_window_list->platform_window<HWND>(), &client_rect); + ScreenToClient(win_window_list->platform_window<HWND>(), &mousepos); // convert to absolute coordinates xpos = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right); @@ -335,10 +335,10 @@ private: POINT mousepos; // get the position relative to the window - GetClientRect(win_window_list.front()->platform_window<HWND>(), &client_rect); + GetClientRect(win_window_list->platform_window<HWND>(), &client_rect); mousepos.x = args.xpos; mousepos.y = args.ypos; - ScreenToClient(win_window_list.front()->platform_window<HWND>(), &mousepos); + ScreenToClient(win_window_list->platform_window<HWND>(), &mousepos); // convert to absolute coordinates mouse.lX = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right); diff --git a/src/osd/modules/input/input_windows.h b/src/osd/modules/input/input_windows.h index d9dd28bac58..85ad2c63326 100644 --- a/src/osd/modules/input/input_windows.h +++ b/src/osd/modules/input/input_windows.h @@ -52,7 +52,7 @@ public: virtual bool should_hide_mouse() { if (winwindow_has_focus() // has focus - && (!video_config.windowed || !win_window_list.front()->win_has_menu()) // not windowed or doesn't have a menu + && (!video_config.windowed || !win_window_list->win_has_menu()) // not windowed or doesn't have a menu && (input_enabled() && !input_paused()) // input enabled and not paused && (mouse_enabled() || lightgun_enabled())) // either mouse or lightgun enabled in the core { diff --git a/src/osd/modules/input/input_winhybrid.cpp b/src/osd/modules/input/input_winhybrid.cpp index c74eb730b71..538abe38da4 100644 --- a/src/osd/modules/input/input_winhybrid.cpp +++ b/src/osd/modules/input/input_winhybrid.cpp @@ -164,7 +164,7 @@ public: goto exit; } - if (!win_window_list.empty() && win_window_list.front()->win_has_menu()) + if (win_window_list != nullptr && win_window_list->win_has_menu()) cooperative_level = DISCL_BACKGROUND | DISCL_NONEXCLUSIVE; // allocate and link in a new device diff --git a/src/osd/modules/osdwindow.cpp b/src/osd/modules/osdwindow.cpp index b9afc8047cd..cde83c3fe7f 100644 --- a/src/osd/modules/osdwindow.cpp +++ b/src/osd/modules/osdwindow.cpp @@ -21,34 +21,33 @@ #include "render/drawsdl.h" #endif -osd_window::~osd_window() -{ -} - -std::unique_ptr<osd_renderer> osd_renderer::make_for_type(int mode, std::shared_ptr<osd_window> window, int extra_flags) +osd_renderer* osd_renderer::make_for_type(int mode, osd_window* window, int extra_flags) { switch(mode) { #ifdef OSD_WINDOWS case VIDEO_MODE_NONE: - return std::make_unique<renderer_none>(window); + return new renderer_none(window); #endif case VIDEO_MODE_BGFX: - return std::make_unique<renderer_bgfx>(window); + return new renderer_bgfx(window); #if (USE_OPENGL) case VIDEO_MODE_OPENGL: - return std::make_unique<renderer_ogl>(window); + return new renderer_ogl(window); #endif #ifdef OSD_WINDOWS case VIDEO_MODE_GDI: - return std::make_unique<renderer_gdi>(window); + return new renderer_gdi(window); case VIDEO_MODE_D3D: - return std::make_unique<renderer_d3d9>(window); + { + osd_renderer *renderer = new renderer_d3d9(window); + return renderer; + } #else case VIDEO_MODE_SDL2ACCEL: - return std::make_unique<renderer_sdl2>(window, extra_flags); + return new renderer_sdl2(window, extra_flags); case VIDEO_MODE_SOFT: - return std::make_unique<renderer_sdl1>(window, extra_flags); + return new renderer_sdl1(window, extra_flags); #endif default: return nullptr; diff --git a/src/osd/modules/osdwindow.h b/src/osd/modules/osdwindow.h index 7f20c7c7b62..850eaa42fd1 100644 --- a/src/osd/modules/osdwindow.h +++ b/src/osd/modules/osdwindow.h @@ -106,9 +106,7 @@ public: int refresh; // decoded refresh }; -class osd_renderer; - -class osd_window : public std::enable_shared_from_this<osd_window> +class osd_window { public: osd_window() @@ -118,24 +116,16 @@ public: #endif m_primlist(nullptr), m_index(0), + m_main(nullptr), m_prescale(1), - m_platform_window(nullptr), - m_renderer(nullptr), - m_main(nullptr) + m_platform_window(nullptr) {} - - virtual ~osd_window(); + virtual ~osd_window() { } virtual render_target *target() = 0; virtual int fullscreen() const = 0; virtual running_machine &machine() const = 0; - osd_renderer &renderer() const { return *m_renderer; } - void set_renderer(std::unique_ptr<osd_renderer> renderer) - { - m_renderer = std::move(renderer); - } - int prescale() const { return m_prescale; }; float pixel_aspect() const { return monitor()->pixel_aspect(); } @@ -162,9 +152,6 @@ public: m_platform_window = window; } - std::shared_ptr<osd_window> main_window() const { return m_main; } - void set_main_window(std::shared_ptr<osd_window> main) { m_main = main; } - // Clips the pointer to the bounds of this window virtual void capture_pointer() = 0; @@ -186,13 +173,12 @@ public: render_primitive_list *m_primlist; osd_window_config m_win_config; - int m_index; + int m_index; + osd_window *m_main; protected: int m_prescale; private: - void *m_platform_window; - std::unique_ptr<osd_renderer> m_renderer; - std::shared_ptr<osd_window> m_main; + void *m_platform_window; }; class osd_renderer @@ -208,23 +194,12 @@ public: static const int FLAG_NEEDS_DOUBLEBUF = 0x0100; static const int FLAG_NEEDS_ASYNCBLIT = 0x0200; - osd_renderer(std::shared_ptr<osd_window> window, const int flags) + osd_renderer(osd_window *window, const int flags) : m_sliders_dirty(false), m_window(window), m_flags(flags) { } virtual ~osd_renderer() { } - std::shared_ptr<osd_window> assert_window() const - { - auto win = m_window.lock(); - assert_always(win != nullptr, "Window weak_ptr is not available!"); - return win; - } - - std::shared_ptr<osd_window> try_getwindow() const - { - return m_window.lock(); - } - + osd_window &window() { return *m_window; } bool has_flags(const int flag) const { return ((m_flags & flag)) == flag; } void set_flags(int aflag) { m_flags |= aflag; } void clear_flags(int aflag) { m_flags &= ~aflag; } @@ -245,7 +220,7 @@ public: virtual void toggle_fsfx() { }; virtual bool sliders_dirty() { return m_sliders_dirty; } - static std::unique_ptr<osd_renderer> make_for_type(int mode, std::shared_ptr<osd_window> window, int extra_flags = FLAG_NONE); + static osd_renderer* make_for_type(int mode, osd_window *window, int extra_flags = FLAG_NONE); protected: virtual void build_slider_list() { } @@ -256,7 +231,7 @@ protected: std::vector<ui_menu_item> m_sliders; private: - std::weak_ptr<osd_window> m_window; + osd_window *m_window; int m_flags; }; diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index 190c324d764..cf6a3eb0895 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -1611,8 +1611,6 @@ void shaders::render_quad(poly_info *poly, int vertnum) curr_texture = poly->get_texture(); curr_poly = poly; - auto win = d3d->assert_window(); - if (PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && curr_texture != nullptr) { curr_screen = curr_screen < num_screens ? curr_screen : 0; @@ -1664,7 +1662,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) { lines_pending = true; - bool swap_xy = win->swap_xy(); + bool swap_xy = d3d->window().swap_xy(); int source_width = swap_xy ? (float)d3d->get_height() : (float)d3d->get_width(); int source_height = swap_xy ? (float)d3d->get_width() : (float)d3d->get_height(); @@ -1691,7 +1689,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) { curr_screen = curr_screen < num_screens ? curr_screen : 0; - bool swap_xy = win->swap_xy(); + bool swap_xy = d3d->window().swap_xy(); int source_width = swap_xy ? (float)d3d->get_height() : (float)d3d->get_width(); int source_height = swap_xy ? (float)d3d->get_width() : (float)d3d->get_height(); @@ -1806,9 +1804,7 @@ d3d_render_target* shaders::get_texture_target(render_primitive *prim, texture_i return nullptr; } - auto win = d3d->assert_window(); - - bool swap_xy = win->swap_xy(); + bool swap_xy = d3d->window().swap_xy(); int target_width = swap_xy ? static_cast<int>(prim->get_quad_height() + 0.5f) : static_cast<int>(prim->get_quad_width() + 0.5f); @@ -1838,9 +1834,7 @@ d3d_render_target* shaders::get_vector_target(render_primitive *prim) return nullptr; } - auto win = d3d->assert_window(); - - bool swap_xy = win->swap_xy(); + bool swap_xy = d3d->window().swap_xy(); int target_width = swap_xy ? static_cast<int>(prim->get_quad_height() + 0.5f) : static_cast<int>(prim->get_quad_width() + 0.5f); @@ -1867,9 +1861,7 @@ d3d_render_target* shaders::get_vector_target(render_primitive *prim) void shaders::create_vector_target(render_primitive *prim) { - auto win = d3d->assert_window(); - - bool swap_xy = win->swap_xy(); + bool swap_xy = d3d->window().swap_xy(); int target_width = swap_xy ? static_cast<int>(prim->get_quad_height() + 0.5f) : static_cast<int>(prim->get_quad_width() + 0.5f); @@ -1981,9 +1973,7 @@ bool shaders::register_texture(render_primitive *prim, texture_info *texture) return false; } - auto win = d3d->assert_window(); - - bool swap_xy = win->swap_xy(); + bool swap_xy = d3d->window().swap_xy(); int target_width = swap_xy ? static_cast<int>(prim->get_quad_height() + 0.5f) : static_cast<int>(prim->get_quad_width() + 0.5f); @@ -2623,8 +2613,6 @@ void uniform::update() hlsl_options *options = shadersys->options; renderer_d3d9 *d3d = shadersys->d3d; - auto win = d3d->assert_window(); - switch (m_id) { case CU_SCREEN_DIMS: @@ -2636,7 +2624,7 @@ void uniform::update() case CU_SOURCE_DIMS: { bool vector_screen = - win->machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; + d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; if (vector_screen) { if (shadersys->curr_render_target) @@ -2684,13 +2672,13 @@ void uniform::update() case CU_SWAP_XY: { - m_shader->set_bool("SwapXY", win->swap_xy()); + m_shader->set_bool("SwapXY", d3d->window().swap_xy()); break; } case CU_VECTOR_SCREEN: { bool vector_screen = - win->machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; + d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; m_shader->set_bool("VectorScreen", vector_screen); break; } diff --git a/src/osd/modules/render/draw13.cpp b/src/osd/modules/render/draw13.cpp index 24bf22c3b27..b4326ff2bdf 100644 --- a/src/osd/modules/render/draw13.cpp +++ b/src/osd/modules/render/draw13.cpp @@ -60,7 +60,7 @@ static inline bool is_transparent(const float &a) // CONSTRUCTOR & DESTRUCTOR //============================================================ -renderer_sdl2::renderer_sdl2(std::shared_ptr<osd_window> window, int extra_flags) +renderer_sdl2::renderer_sdl2(osd_window *window, int extra_flags) : osd_renderer(window, FLAG_NEEDS_OPENGL | extra_flags) , m_sdl_renderer(nullptr) , m_blittimer(0) @@ -434,12 +434,10 @@ int renderer_sdl2::create() SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); } - auto win = assert_window(); - if (video_config.waitvsync) - m_sdl_renderer = SDL_CreateRenderer(win->platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); + m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); else - m_sdl_renderer = SDL_CreateRenderer(win->platform_window<SDL_Window*>(), -1, SDL_RENDERER_ACCELERATED); + m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_ACCELERATED); if (!m_sdl_renderer) { @@ -483,15 +481,11 @@ int renderer_sdl2::xy_to_render_target(int x, int y, int *xt, int *yt) void renderer_sdl2::destroy_all_textures() { - auto win = assert_window(); - if (win == nullptr) - return; - - if(win->m_primlist) + if(window().m_primlist) { - win->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); m_texlist.reset(); - win->m_primlist->release_lock(); + window().m_primlist->release_lock(); } else m_texlist.reset(); @@ -512,8 +506,7 @@ int renderer_sdl2::draw(int update) return 0; } - auto win = assert_window(); - osd_dim wdim = win->get_size(); + osd_dim wdim = window().get_size(); if (has_flags(FI_CHANGED) || (wdim.width() != m_width) || (wdim.height() != m_height)) { @@ -560,10 +553,10 @@ int renderer_sdl2::draw(int update) m_last_hofs = hofs; m_last_vofs = vofs; - win->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); // now draw - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *window().m_primlist) { Uint8 sr, sg, sb, sa; @@ -593,7 +586,7 @@ int renderer_sdl2::draw(int update) } } - win->m_primlist->release_lock(); + window().m_primlist->release_lock(); m_last_blit_pixels = blit_pixels; m_last_blit_time = -osd_ticks(); @@ -937,8 +930,7 @@ texture_info * renderer_sdl2::texture_update(const render_primitive &prim) quad_setup_data setup; texture_info *texture; - auto win = assert_window(); - setup.compute(prim, win->prescale()); + setup.compute(prim, window().prescale()); texture = texture_find(prim, setup); @@ -965,16 +957,12 @@ texture_info * renderer_sdl2::texture_update(const render_primitive &prim) render_primitive_list *renderer_sdl2::get_primitives() { - auto win = assert_window(); - if (win == nullptr) - return nullptr; - - osd_dim nd = win->get_size(); + osd_dim nd = window().get_size(); if (nd != m_blit_dim) { m_blit_dim = nd; notify_changed(); } - win->target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), win->pixel_aspect()); - return &win->target()->get_primitives(); + window().target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), window().pixel_aspect()); + return &window().target()->get_primitives(); } diff --git a/src/osd/modules/render/draw13.h b/src/osd/modules/render/draw13.h index e242749ba10..634c1debf6f 100644 --- a/src/osd/modules/render/draw13.h +++ b/src/osd/modules/render/draw13.h @@ -149,7 +149,7 @@ struct copy_info_t class renderer_sdl2 : public osd_renderer { public: - renderer_sdl2(std::shared_ptr<osd_window> window, int extra_flags); + renderer_sdl2(osd_window *window, int extra_flags); virtual ~renderer_sdl2() { diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp index 84f1ff0bd6f..479cea4f3b2 100644 --- a/src/osd/modules/render/drawbgfx.cpp +++ b/src/osd/modules/render/drawbgfx.cpp @@ -77,7 +77,7 @@ uint32_t renderer_bgfx::s_current_view = 0; // renderer_bgfx - constructor //============================================================ -renderer_bgfx::renderer_bgfx(std::shared_ptr<osd_window> w) +renderer_bgfx::renderer_bgfx(osd_window *w) : osd_renderer(w, FLAG_NONE) , m_options(downcast<osd_options &>(w->machine().options())) , m_dimensions(0, 0) @@ -85,7 +85,7 @@ renderer_bgfx::renderer_bgfx(std::shared_ptr<osd_window> w) , m_avi_writer(nullptr) , m_avi_target(nullptr) { - m_options = downcast<osd_options &>(assert_window()->machine().options()); + m_options = downcast<osd_options &>(window().machine().options()); } //============================================================ @@ -146,11 +146,10 @@ static void* sdlNativeWindowHandle(SDL_Window* _window) int renderer_bgfx::create() { // create renderer - auto win = assert_window(); - osd_dim wdim = win->get_size(); - m_width[win->m_index] = wdim.width(); - m_height[win->m_index] = wdim.height(); - if (win->m_index == 0) + osd_dim wdim = window().get_size(); + m_width[window().m_index] = wdim.width(); + m_height[window().m_index] = wdim.height(); + if (window().m_index == 0) { if (!s_window_set) { @@ -165,9 +164,9 @@ int renderer_bgfx::create() bgfx::setPlatformData(blank_pd); } #ifdef OSD_WINDOWS - bgfx::winSetHwnd(win->platform_window<HWND>()); + bgfx::winSetHwnd(window().platform_window<HWND>()); #else - bgfx::sdlSetWindow(win->platform_window<SDL_Window*>()); + bgfx::sdlSetWindow(window().platform_window<SDL_Window*>()); #endif std::string backend(m_options.bgfx_backend()); if (backend == "auto") @@ -199,7 +198,7 @@ int renderer_bgfx::create() printf("Unknown backend type '%s', going with auto-detection\n", backend.c_str()); bgfx::init(); } - bgfx::reset(m_width[win->m_index], m_height[win->m_index], video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); + bgfx::reset(m_width[window().m_index], m_height[window().m_index], video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); // Enable debug text. bgfx::setDebug(m_options.bgfx_debug() ? BGFX_DEBUG_STATS : BGFX_DEBUG_TEXT); m_dimensions = osd_dim(m_width[0], m_height[0]); @@ -211,14 +210,14 @@ int renderer_bgfx::create() m_shaders = new shader_manager(m_options); m_effects = new effect_manager(m_options, *m_shaders); - if (win->m_index != 0) + if (window().m_index != 0) { #ifdef OSD_WINDOWS - m_framebuffer = m_targets->create_backbuffer(win->platform_window<HWND>(), m_width[win->m_index], m_height[win->m_index]); + m_framebuffer = m_targets->create_backbuffer(window().platform_window<HWND>(), m_width[window().m_index], m_height[window().m_index]); #else - m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(win->platform_window<SDL_Window*>()), m_width[win->m_index], m_height[win->m_index]); + m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().platform_window<SDL_Window*>()), m_width[window().m_index], m_height[window().m_index]); #endif - bgfx::touch(win->m_index); + bgfx::touch(window().m_index); } // Create program from shaders. @@ -232,7 +231,7 @@ int renderer_bgfx::create() m_screen_effect[2] = m_effects->effect("screen_multiply"); m_screen_effect[3] = m_effects->effect("screen_add"); - m_chains = new chain_manager(win->machine(), m_options, *m_textures, *m_targets, *m_effects, win->m_index, *this); + m_chains = new chain_manager(window().machine(), m_options, *m_textures, *m_targets, *m_effects, window().m_index, *this); m_sliders_dirty = true; uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT; @@ -252,8 +251,7 @@ int renderer_bgfx::create() void renderer_bgfx::record() { - auto win = assert_window(); - if (m_avi_writer == nullptr || win->m_index > 0) + if (m_avi_writer == nullptr || window().m_index > 0) { return; } @@ -650,16 +648,15 @@ uint32_t renderer_bgfx::u32Color(uint32_t r, uint32_t g, uint32_t b, uint32_t a int renderer_bgfx::draw(int update) { - auto win = assert_window(); - int window_index = win->m_index; + int window_index = window().m_index; if (window_index == 0) { s_current_view = 0; if (m_avi_writer == nullptr) { - uint32_t width = win->get_size().width(); - uint32_t height = win->get_size().height(); - m_avi_writer = new avi_write(win->machine(), width, height); + uint32_t width = window().get_size().width(); + uint32_t height = window().get_size().height(); + m_avi_writer = new avi_write(window().machine(), width, height); m_avi_data = new uint8_t[width * height * 4]; m_avi_bitmap.allocate(width, height); } @@ -669,13 +666,13 @@ int renderer_bgfx::draw(int update) m_ui_view = -1; // Set view 0 default viewport. - osd_dim wdim = win->get_size(); + osd_dim wdim = window().get_size(); m_width[window_index] = wdim.width(); m_height[window_index] = wdim.height(); - win->m_primlist->acquire_lock(); - s_current_view += m_chains->handle_screen_chains(s_current_view, win->m_primlist->first(), *win.get()); - win->m_primlist->release_lock(); + window().m_primlist->acquire_lock(); + s_current_view += m_chains->handle_screen_chains(s_current_view, window().m_primlist->first(), window()); + window().m_primlist->release_lock(); bool skip_frame = update_dimensions(); if (skip_frame) @@ -692,12 +689,12 @@ int renderer_bgfx::draw(int update) s_current_view = m_max_view; } - win->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); // Mark our texture atlas as dirty if we need to do so bool atlas_valid = update_atlas(); - render_primitive *prim = win->m_primlist->first(); + render_primitive *prim = window().m_primlist->first(); std::vector<void*> sources; while (prim != nullptr) { @@ -737,7 +734,7 @@ int renderer_bgfx::draw(int update) } } - win->m_primlist->release_lock(); + window().m_primlist->release_lock(); // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. @@ -777,8 +774,7 @@ void renderer_bgfx::update_recording() void renderer_bgfx::add_audio_to_recording(const INT16 *buffer, int samples_this_frame) { - auto win = assert_window(); - if (m_avi_writer != nullptr && m_avi_writer->recording() && win->m_index == 0) + if (m_avi_writer != nullptr && m_avi_writer->recording() && window().m_index == 0) { m_avi_writer->audio_frame(buffer, samples_this_frame); } @@ -786,9 +782,7 @@ void renderer_bgfx::add_audio_to_recording(const INT16 *buffer, int samples_this bool renderer_bgfx::update_dimensions() { - auto win = assert_window(); - - const uint32_t window_index = win->m_index; + const uint32_t window_index = window().m_index; const uint32_t width = m_width[window_index]; const uint32_t height = m_height[window_index]; @@ -804,14 +798,14 @@ bool renderer_bgfx::update_dimensions() { if ((m_dimensions != osd_dim(width, height))) { - bgfx::reset(win->main_window()->get_size().width(), win->main_window()->get_size().height(), video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); + bgfx::reset(window().m_main->get_size().width(), window().m_main->get_size().height(), video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); m_dimensions = osd_dim(width, height); delete m_framebuffer; #ifdef OSD_WINDOWS - m_framebuffer = m_targets->create_backbuffer(win->platform_window<HWND>(), width, height); + m_framebuffer = m_targets->create_backbuffer(window().platform_window<HWND>(), width, height); #else - m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(win->platform_window<SDL_Window*>()), width, height); + m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().platform_window<SDL_Window*>()), width, height); #endif bgfx::setViewFrameBuffer(s_current_view, m_framebuffer->target()); @@ -826,9 +820,7 @@ bool renderer_bgfx::update_dimensions() void renderer_bgfx::setup_view(uint32_t view_index, bool screen) { - auto win = assert_window(); - - const uint32_t window_index = win->m_index; + const uint32_t window_index = window().m_index; const uint32_t width = m_width[window_index]; const uint32_t height = m_height[window_index]; @@ -853,7 +845,7 @@ void renderer_bgfx::setup_view(uint32_t view_index, bool screen) { m_seen_views[view_index] = true; #endif - if (m_avi_writer != nullptr && m_avi_writer->recording() && win->m_index == 0) + if (m_avi_writer != nullptr && m_avi_writer->recording() && window().m_index == 0) { bgfx::setViewFrameBuffer(view_index, m_avi_target->target()); } @@ -865,8 +857,7 @@ void renderer_bgfx::setup_view(uint32_t view_index, bool screen) void renderer_bgfx::setup_matrices(uint32_t view_index, bool screen) { - auto win = assert_window(); - const uint32_t window_index = win->m_index; + const uint32_t window_index = window().m_index; const uint32_t width = m_width[window_index]; const uint32_t height = m_height[window_index]; @@ -1073,9 +1064,8 @@ bool renderer_bgfx::check_for_dirty_atlas() { bool atlas_dirty = false; - auto win = assert_window(); std::map<UINT32, rectangle_packer::packable_rectangle> acquired_infos; - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *window().m_primlist) { bool pack = prim.packable(PACKABLE_SIZE); if (prim.type == render_primitive::QUAD && prim.texture.base != nullptr && pack) diff --git a/src/osd/modules/render/drawbgfx.h b/src/osd/modules/render/drawbgfx.h index 7cc3bab9e47..1a21b5c8259 100644 --- a/src/osd/modules/render/drawbgfx.h +++ b/src/osd/modules/render/drawbgfx.h @@ -32,7 +32,7 @@ class avi_write; class renderer_bgfx : public osd_renderer, public slider_dirty_notifier { public: - renderer_bgfx(std::shared_ptr<osd_window> w); + renderer_bgfx(osd_window *w); virtual ~renderer_bgfx(); static void init(running_machine &machine) { } @@ -55,10 +55,6 @@ public: virtual render_primitive_list *get_primitives() override { - auto win = try_getwindow(); - if (win == nullptr) - return nullptr; - // determines whether the screen container is transformed by the chain's shaders bool chain_transform = false; @@ -69,10 +65,10 @@ public: chain_transform = chain->transform(); } - osd_dim wdim = win->get_size(); - win->target()->set_bounds(wdim.width(), wdim.height(), win->pixel_aspect()); - win->target()->set_transform_container(!chain_transform); - return &win->target()->get_primitives(); + osd_dim wdim = window().get_size(); + window().target()->set_bounds(wdim.width(), wdim.height(), window().pixel_aspect()); + window().target()->set_transform_container(!chain_transform); + return &window().target()->get_primitives(); } static const char* WINDOW_PREFIX; diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp index 6c682a80409..e28c3e7928a 100644 --- a/src/osd/modules/render/drawd3d.cpp +++ b/src/osd/modules/render/drawd3d.cpp @@ -199,22 +199,19 @@ void renderer_d3d9::save() render_primitive_list *renderer_d3d9::get_primitives() { RECT client; - auto win = try_getwindow(); - if (win == nullptr) - return nullptr; - GetClientRectExceptMenu(win->platform_window<HWND>(), &client, win->fullscreen()); + GetClientRectExceptMenu(window().platform_window<HWND>(), &client, window().fullscreen()); if (rect_width(&client) > 0 && rect_height(&client) > 0) { - win->target()->set_bounds(rect_width(&client), rect_height(&client), win->pixel_aspect()); - win->target()->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh()); + window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect()); + window().target()->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh()); } if (m_shaders != nullptr) { // do not transform primitives (scale, offset) if shaders are enabled, the shaders will handle the transformation - win->target()->set_transform_container(!m_shaders->enabled()); + window().target()->set_transform_container(!m_shaders->enabled()); } - return &win->target()->get_primitives(); + return &window().target()->get_primitives(); } @@ -413,10 +410,8 @@ d3d_texture_manager::d3d_texture_manager(renderer_d3d9 *d3d) } osd_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB"); - auto win = d3d->assert_window(); - // set the max texture size - win->target()->set_max_texture_size(m_texture_max_width, m_texture_max_height); + d3d->window().target()->set_max_texture_size(m_texture_max_width, m_texture_max_height); osd_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height); } @@ -426,11 +421,9 @@ d3d_texture_manager::~d3d_texture_manager() void d3d_texture_manager::create_resources() { - auto win = m_renderer->assert_window(); - // experimental: load a PNG to use for vector rendering; it is treated // as a brightness map - emu_file file(win->machine().options().art_path(), OPEN_FLAG_READ); + emu_file file(m_renderer->window().machine().options().art_path(), OPEN_FLAG_READ); render_load_png(m_vector_bitmap, file, nullptr, "vector.png"); if (m_vector_bitmap.valid()) { @@ -454,7 +447,7 @@ void d3d_texture_manager::create_resources() texture.seqid = 0; // now create it - m_default_texture = global_alloc(texture_info(this, &texture, win->prescale(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32))); + m_default_texture = global_alloc(texture_info(this, &texture, m_renderer->window().prescale(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32))); } // experimental: if we have a vector bitmap, create a texture for it @@ -471,7 +464,7 @@ void d3d_texture_manager::create_resources() texture.seqid = 0; // now create it - m_vector_texture = global_alloc(texture_info(this, &texture, win->prescale(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32))); + m_vector_texture = global_alloc(texture_info(this, &texture, m_renderer->window().prescale(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32))); } } @@ -571,7 +564,7 @@ texture_info *d3d_texture_manager::find_texinfo(const render_texinfo *texinfo, U return nullptr; } -renderer_d3d9::renderer_d3d9(std::shared_ptr<osd_window> window) +renderer_d3d9::renderer_d3d9(osd_window *window) : osd_renderer(window, FLAG_NONE), m_adapter(0), m_width(0), m_height(0), m_refresh(0), m_create_error_count(0), m_device(nullptr), m_gamma_supported(0), m_pixformat(), m_vertexbuf(nullptr), m_lockedbuf(nullptr), m_numverts(0), m_vectorbatch(nullptr), m_batchindex(0), m_numpolys(0), m_restarting(false), m_mod2x_supported(0), m_mod4x_supported(0), m_screen_format(), m_last_texture(nullptr), m_last_texture_flags(0), m_last_blendenable(0), m_last_blendop(0), m_last_blendsrc(0), m_last_blenddst(0), m_last_filter(0), @@ -588,8 +581,7 @@ int renderer_d3d9::initialize() } // create the device immediately for the full screen case (defer for window mode) - auto win = assert_window(); - if (win->fullscreen() && device_create(win->main_window()->platform_window<HWND>())) + if (window().fullscreen() && device_create(window().m_main->platform_window<HWND>())) { return false; } @@ -599,10 +591,8 @@ int renderer_d3d9::initialize() int renderer_d3d9::pre_window_draw_check() { - auto win = assert_window(); - // if we're in the middle of resizing, leave things alone - if (win->m_resize_state == RESIZE_STATE_RESIZING) + if (window().m_resize_state == RESIZE_STATE_RESIZING) return 0; // if we're restarting the renderer, leave things alone @@ -624,7 +614,7 @@ int renderer_d3d9::pre_window_draw_check() } // in window mode, we need to track the window size - if (!win->fullscreen() || m_device == nullptr) + if (!window().fullscreen() || m_device == nullptr) { // if the size changes, skip this update since the render target will be out of date if (update_window_size()) @@ -640,9 +630,7 @@ int renderer_d3d9::pre_window_draw_check() void d3d_texture_manager::update_textures() { - auto win = m_renderer->assert_window(); - - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *m_renderer->window().m_primlist) { if (prim.texture.base != nullptr) { @@ -657,7 +645,7 @@ void d3d_texture_manager::update_textures() else { // if there isn't one, create a new texture - texture = global_alloc(texture_info(this, &prim.texture, win->prescale(), prim.flags)); + texture = global_alloc(texture_info(this, &prim.texture, m_renderer->window().prescale(), prim.flags)); } } else @@ -693,14 +681,12 @@ void d3d_texture_manager::update_textures() void renderer_d3d9::begin_frame() { - auto win = assert_window(); - HRESULT result = (*d3dintf->device.clear)(m_device, 0, nullptr, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); m_shaders->begin_frame(); - win->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); // first update any textures m_texture_manager->update_textures(); @@ -720,7 +706,7 @@ void renderer_d3d9::begin_frame() // loop over line primitives m_line_count = 0; - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *window().m_primlist) { if (prim.type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim.flags)) { @@ -731,10 +717,8 @@ void renderer_d3d9::begin_frame() void renderer_d3d9::process_primitives() { - auto win = assert_window(); - // Rotating index for vector time offsets - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *window().m_primlist) { switch (prim.type) { @@ -764,9 +748,7 @@ void renderer_d3d9::process_primitives() void renderer_d3d9::end_frame() { - auto win = assert_window(); - - win->m_primlist->release_lock(); + window().m_primlist->release_lock(); // flush any pending polygons primitive_flush_pending(); @@ -837,8 +819,6 @@ try_again: } } - auto win = assert_window(); - // initialize the D3D presentation parameters memset(&m_presentation, 0, sizeof(m_presentation)); m_presentation.BackBufferWidth = m_width; @@ -847,13 +827,13 @@ try_again: m_presentation.BackBufferCount = video_config.triplebuf ? 2 : 1; m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE; m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD; - m_presentation.hDeviceWindow = win->platform_window<HWND>(); - m_presentation.Windowed = !win->fullscreen() || win->win_has_menu(); + m_presentation.hDeviceWindow = window().platform_window<HWND>(); + m_presentation.Windowed = !window().fullscreen() || window().win_has_menu(); m_presentation.EnableAutoDepthStencil = FALSE; m_presentation.AutoDepthStencilFormat = D3DFMT_D16; m_presentation.Flags = 0; m_presentation.FullScreen_RefreshRateInHz = m_refresh; - m_presentation.PresentationInterval = ((video_config.triplebuf && win->fullscreen()) || + m_presentation.PresentationInterval = ((video_config.triplebuf && window().fullscreen()) || video_config.waitvsync || video_config.syncrefresh) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; @@ -881,10 +861,10 @@ try_again: osd_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height); // set the gamma if we need to - if (win->fullscreen()) + if (window().fullscreen()) { // only set the gamma if it's not 1.0f - windows_options &options = downcast<windows_options &>(win->machine().options()); + windows_options &options = downcast<windows_options &>(window().machine().options()); float brightness = options.full_screen_brightness(); float contrast = options.full_screen_contrast(); float gamma = options.full_screen_gamma(); @@ -916,7 +896,7 @@ try_again: } m_shaders = (shaders*)global_alloc_clear<shaders>(); - m_shaders->init(d3dintf, &win->machine(), this); + m_shaders->init(d3dintf, &window().machine(), this); m_sliders.clear(); int failed = m_shaders->create_resources(false, m_sliders); @@ -1214,15 +1194,13 @@ int renderer_d3d9::config_adapter_mode() return 1; } - auto win = assert_window(); - // choose a resolution: window mode case - if (!win->fullscreen() || !video_config.switchres || win->win_has_menu()) + if (!window().fullscreen() || !video_config.switchres || window().win_has_menu()) { RECT client; // bounds are from the window client rect - GetClientRectExceptMenu(win->platform_window<HWND>(), &client, win->fullscreen()); + GetClientRectExceptMenu(window().platform_window<HWND>(), &client, window().fullscreen()); m_width = client.right - client.left; m_height = client.bottom - client.top; @@ -1233,7 +1211,7 @@ int renderer_d3d9::config_adapter_mode() // make sure it's a pixel format we can get behind if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8) { - osd_printf_error("Device %s currently in an unsupported mode\n", win->monitor()->devicename()); + osd_printf_error("Device %s currently in an unsupported mode\n", window().monitor()->devicename()); return 1; } } @@ -1253,10 +1231,10 @@ int renderer_d3d9::config_adapter_mode() } // see if we can handle the device type - result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !win->fullscreen()); + result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !window().fullscreen()); if (result != D3D_OK) { - osd_printf_error("Proposed video mode not supported on device %s\n", win->monitor()->devicename()); + osd_printf_error("Proposed video mode not supported on device %s\n", window().monitor()->devicename()); return 1; } return 0; @@ -1271,8 +1249,6 @@ int renderer_d3d9::get_adapter_for_monitor() { int maxadapter = (*d3dintf->d3d.get_adapter_count)(d3dintf); - auto win = assert_window(); - // iterate over adapters until we error or find a match for (int adapternum = 0; adapternum < maxadapter; adapternum++) { @@ -1280,7 +1256,7 @@ int renderer_d3d9::get_adapter_for_monitor() HMONITOR curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum); // if we match the proposed monitor, this is it - if (curmonitor == *((HMONITOR *)win->monitor()->oshandle())) + if (curmonitor == *((HMONITOR *)window().monitor()->oshandle())) { return adapternum; } @@ -1301,10 +1277,8 @@ void renderer_d3d9::pick_best_mode() INT32 minwidth, minheight; float best_score = 0.0f; - auto win = assert_window(); - // determine the refresh rate of the primary screen - const screen_device *primary_screen = win->machine().config().first_screen(); + const screen_device *primary_screen = window().machine().config().first_screen(); if (primary_screen != nullptr) { target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds()); @@ -1314,7 +1288,7 @@ void renderer_d3d9::pick_best_mode() // note: technically we should not be calling this from an alternate window // thread; however, it is only done during init time, and the init code on // the main thread is waiting for us to finish, so it is safe to do so here - win->target()->compute_minimum_size(minwidth, minheight); + window().target()->compute_minimum_size(minwidth, minheight); // use those as the target for now INT32 target_width = minwidth; @@ -1349,7 +1323,7 @@ void renderer_d3d9::pick_best_mode() size_score *= 0.1f; // if we're looking for a particular mode, that's a winner - if (mode.Width == win->m_win_config.width && mode.Height == win->m_win_config.height) + if (mode.Width == window().m_win_config.width && mode.Height == window().m_win_config.height) size_score = 2.0f; // compute refresh score @@ -1360,7 +1334,7 @@ void renderer_d3d9::pick_best_mode() refresh_score *= 0.1f; // if we're looking for a particular refresh, make sure it matches - if (mode.RefreshRate == win->m_win_config.refresh) + if (mode.RefreshRate == window().m_win_config.refresh) refresh_score = 2.0f; // weight size and refresh equally @@ -1387,33 +1361,31 @@ void renderer_d3d9::pick_best_mode() int renderer_d3d9::update_window_size() { - auto win = assert_window(); - // get the current window bounds RECT client; - GetClientRectExceptMenu(win->platform_window<HWND>(), &client, win->fullscreen()); + GetClientRectExceptMenu(window().platform_window<HWND>(), &client, window().fullscreen()); // if we have a device and matching width/height, nothing to do if (m_device != nullptr && rect_width(&client) == m_width && rect_height(&client) == m_height) { // clear out any pending resizing if the area didn't change - if (win->m_resize_state == RESIZE_STATE_PENDING) - win->m_resize_state = RESIZE_STATE_NORMAL; + if (window().m_resize_state == RESIZE_STATE_PENDING) + window().m_resize_state = RESIZE_STATE_NORMAL; return FALSE; } // if we're in the middle of resizing, leave it alone as well - if (win->m_resize_state == RESIZE_STATE_RESIZING) + if (window().m_resize_state == RESIZE_STATE_RESIZING) return FALSE; // set the new bounds and create the device again m_width = rect_width(&client); m_height = rect_height(&client); - if (device_create(win->main_window()->platform_window<HWND>())) + if (window().m_main != nullptr && device_create(window().m_main->platform_window<HWND>())) return FALSE; // reset the resize state to normal, and indicate we made a change - win->m_resize_state = RESIZE_STATE_NORMAL; + window().m_resize_state = RESIZE_STATE_NORMAL; return TRUE; } @@ -1424,9 +1396,7 @@ int renderer_d3d9::update_window_size() void renderer_d3d9::batch_vectors() { - auto win = assert_window(); - - windows_options &options = downcast<windows_options &>(win->machine().options()); + windows_options &options = downcast<windows_options &>(window().machine().options()); float quad_width = 0.0f; float quad_height = 0.0f; @@ -1439,7 +1409,7 @@ void renderer_d3d9::batch_vectors() int line_index = 0; float period = options.screen_vector_time_period(); UINT32 cached_flags = 0; - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *window().m_primlist) { switch (prim.type) { @@ -1477,15 +1447,15 @@ void renderer_d3d9::batch_vectors() if (m_shaders->enabled()) { bool orientation_swap_xy = - (win->machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY; + (window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY; bool rotation_swap_xy = - (win->target()->orientation() & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY; + (window().target()->orientation() & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY; bool swap_xy = orientation_swap_xy ^ rotation_swap_xy; - bool rotation_0 = win->target()->orientation() == ROT0; - bool rotation_90 = win->target()->orientation() == ROT90; - bool rotation_180 = win->target()->orientation() == ROT180; - bool rotation_270 = win->target()->orientation() == ROT270; + bool rotation_0 = window().target()->orientation() == ROT0; + bool rotation_90 = window().target()->orientation() == ROT90; + bool rotation_180 = window().target()->orientation() == ROT180; + bool rotation_270 = window().target()->orientation() == ROT270; bool flip_x = ((rotation_0 || rotation_270) && orientation_swap_xy) || ((rotation_180 || rotation_270) && !orientation_swap_xy); @@ -2104,9 +2074,7 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t m_yprescale--; } - auto win = m_renderer->assert_window(); - - int prescale = win->prescale(); + int prescale = m_renderer->window().prescale(); if (m_xprescale != prescale || m_yprescale != prescale) { osd_printf_verbose("Direct3D: adjusting prescale from %dx%d to %dx%d\n", prescale, prescale, m_xprescale, m_yprescale); @@ -2973,7 +2941,7 @@ bool d3d_render_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_w } bool vector_screen = - d3d->assert_window()->machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; + d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; float scale_factor = 0.75f; int scale_count = vector_screen ? MAX_BLOOM_COUNT : MAX_BLOOM_COUNT / 2; diff --git a/src/osd/modules/render/drawd3d.h b/src/osd/modules/render/drawd3d.h index 3b1083881b3..e38d967e53a 100644 --- a/src/osd/modules/render/drawd3d.h +++ b/src/osd/modules/render/drawd3d.h @@ -40,7 +40,7 @@ class poly_info; class renderer_d3d9 : public osd_renderer { public: - renderer_d3d9(std::shared_ptr<osd_window> window); + renderer_d3d9(osd_window *window); virtual ~renderer_d3d9(); static bool init(running_machine &machine); diff --git a/src/osd/modules/render/drawgdi.cpp b/src/osd/modules/render/drawgdi.cpp index 6d6b98218b6..bfc949e5296 100644 --- a/src/osd/modules/render/drawgdi.cpp +++ b/src/osd/modules/render/drawgdi.cpp @@ -45,14 +45,10 @@ int renderer_gdi::create() render_primitive_list *renderer_gdi::get_primitives() { - auto win = try_getwindow(); - if (win == nullptr) - return nullptr; - RECT client; - GetClientRect(win->platform_window<HWND>(), &client); - win->target()->set_bounds(rect_width(&client), rect_height(&client), win->pixel_aspect()); - return &win->target()->get_primitives(); + GetClientRect(window().platform_window<HWND>(), &client); + window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect()); + return &window().target()->get_primitives(); } //============================================================ @@ -61,15 +57,13 @@ render_primitive_list *renderer_gdi::get_primitives() int renderer_gdi::draw(const int update) { - auto win = assert_window(); - // we don't have any special resize behaviors - if (win->m_resize_state == RESIZE_STATE_PENDING) - win->m_resize_state = RESIZE_STATE_NORMAL; + if (window().m_resize_state == RESIZE_STATE_PENDING) + window().m_resize_state = RESIZE_STATE_NORMAL; // get the target bounds RECT bounds; - GetClientRect(win->platform_window<HWND>(), &bounds); + GetClientRect(window().platform_window<HWND>(), &bounds); // compute width/height/pitch of target int width = rect_width(&bounds); @@ -85,16 +79,16 @@ int renderer_gdi::draw(const int update) } // draw the primitives to the bitmap - win->m_primlist->acquire_lock(); - software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*win->m_primlist, m_bmdata, width, height, pitch); - win->m_primlist->release_lock(); + window().m_primlist->acquire_lock(); + software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, m_bmdata, width, height, pitch); + window().m_primlist->release_lock(); // fill in bitmap-specific info m_bminfo.bmiHeader.biWidth = pitch; m_bminfo.bmiHeader.biHeight = -height; // blit to the screen - StretchDIBits(win->m_dc, 0, 0, width, height, + StretchDIBits(window().m_dc, 0, 0, width, height, 0, 0, width, height, m_bmdata, &m_bminfo, DIB_RGB_COLORS, SRCCOPY); return 0; diff --git a/src/osd/modules/render/drawgdi.h b/src/osd/modules/render/drawgdi.h index 319ef9802e6..7606bf14738 100644 --- a/src/osd/modules/render/drawgdi.h +++ b/src/osd/modules/render/drawgdi.h @@ -29,7 +29,7 @@ class renderer_gdi : public osd_renderer { public: - renderer_gdi(std::shared_ptr<osd_window> window) + renderer_gdi(osd_window *window) : osd_renderer(window, FLAG_NONE) , m_bmdata(nullptr) , m_bmsize(0) diff --git a/src/osd/modules/render/drawnone.cpp b/src/osd/modules/render/drawnone.cpp index f6bde9d868f..5e261daafe2 100644 --- a/src/osd/modules/render/drawnone.cpp +++ b/src/osd/modules/render/drawnone.cpp @@ -21,12 +21,8 @@ render_primitive_list *renderer_none::get_primitives() { - auto win = try_getwindow(); - if (win == nullptr) - return nullptr; - RECT client; - GetClientRect(win->platform_window<HWND>(), &client); - win->target()->set_bounds(rect_width(&client), rect_height(&client), win->pixel_aspect()); - return &win->target()->get_primitives(); + GetClientRect(window().platform_window<HWND>(), &client); + window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect()); + return &window().target()->get_primitives(); } diff --git a/src/osd/modules/render/drawnone.h b/src/osd/modules/render/drawnone.h index 1fc4a50b689..08873860e61 100644 --- a/src/osd/modules/render/drawnone.h +++ b/src/osd/modules/render/drawnone.h @@ -17,7 +17,7 @@ class renderer_none : public osd_renderer { public: - renderer_none(std::shared_ptr<osd_window> window) + renderer_none(osd_window *window) : osd_renderer(window, FLAG_NONE) { } virtual ~renderer_none() { } diff --git a/src/osd/modules/render/drawogl.cpp b/src/osd/modules/render/drawogl.cpp index 01d8085efd7..a7ffe24a5df 100644 --- a/src/osd/modules/render/drawogl.cpp +++ b/src/osd/modules/render/drawogl.cpp @@ -559,13 +559,11 @@ void renderer_ogl::initialize_gl() int renderer_ogl::create() { - auto win = assert_window(); - // create renderer #if defined(OSD_WINDOWS) - m_gl_context = global_alloc(win_gl_context(win->platform_window<HWND>())); + m_gl_context = global_alloc(win_gl_context(window().platform_window<HWND>())); #else - m_gl_context = global_alloc(sdl_gl_context(win->platform_window<SDL_Window*>())); + m_gl_context = global_alloc(sdl_gl_context(window().platform_window<SDL_Window*>())); #endif if (m_gl_context->LastErrorMsg() != nullptr) { @@ -629,19 +627,12 @@ void renderer_ogl::destroy_all_textures() if ( !m_initialized ) return; - auto win = try_getwindow(); - - // During destroy this can get called - // and the window is no longer available - if (win == nullptr) - return; - m_gl_context->MakeCurrent(); - if(win->m_primlist) + if(window().m_primlist) { lock=TRUE; - win->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); } glFinish(); @@ -703,7 +694,7 @@ void renderer_ogl::destroy_all_textures() m_initialized = 0; if (lock) - win->m_primlist->release_lock(); + window().m_primlist->release_lock(); } //============================================================ // loadGLExtensions @@ -923,7 +914,7 @@ void renderer_ogl::loadGLExtensions() if ( m_useglsl ) { - if (assert_window()->prescale() != 1 ) + if ( window().prescale() != 1 ) { m_useglsl = 0; if (_once) @@ -1032,9 +1023,7 @@ int renderer_ogl::draw(const int update) } #endif - auto win = assert_window(); - - osd_dim wdim = win->get_size(); + osd_dim wdim = window().get_size(); if (has_flags(FI_CHANGED) || (wdim.width() != m_width) || (wdim.height() != m_height)) { @@ -1085,7 +1074,7 @@ int renderer_ogl::draw(const int update) // we're doing nothing 3d, so the Z-buffer is currently not interesting glDisable(GL_DEPTH_TEST); - if (win->machine().options().antialias()) + if (window().machine().options().antialias()) { // enable antialiasing for lines glEnable(GL_LINE_SMOOTH); @@ -1165,10 +1154,10 @@ int renderer_ogl::draw(const int update) m_last_hofs = hofs; m_last_vofs = vofs; - win->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); // now draw - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *window().m_primlist) { int i; @@ -1384,7 +1373,7 @@ int renderer_ogl::draw(const int update) pendingPrimitive=GL_NO_PRIMITIVE; } - win->m_primlist->release_lock(); + window().m_primlist->release_lock(); m_init_context = 0; m_gl_context->SwapBuffer(); @@ -1519,10 +1508,8 @@ void renderer_ogl::texture_compute_size_subroutine(ogl_texture_info *texture, UI texture->xprescale--; while (texture->yprescale > 1 && height_create * texture->yprescale > m_texture_max_height) texture->yprescale--; - - auto win = assert_window(); - if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != win->prescale() || texture->yprescale != win->prescale())) - osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", win->prescale(), win->prescale(), texture->xprescale, texture->yprescale); + if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().prescale() || texture->yprescale != window().prescale())) + osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().prescale(), window().prescale(), texture->xprescale, texture->yprescale); width *= texture->xprescale; height *= texture->yprescale; @@ -1884,9 +1871,8 @@ ogl_texture_info *renderer_ogl::texture_create(const render_texinfo *texsource, texture->texinfo.seqid = -1; // force set data if (PRIMFLAG_GET_SCREENTEX(flags)) { - auto win = assert_window(); - texture->xprescale = win->prescale(); - texture->yprescale = win->prescale(); + texture->xprescale = window().prescale(); + texture->yprescale = window().prescale(); } else { diff --git a/src/osd/modules/render/drawogl.h b/src/osd/modules/render/drawogl.h index c96c3a45b1b..a7d664c3433 100644 --- a/src/osd/modules/render/drawogl.h +++ b/src/osd/modules/render/drawogl.h @@ -95,7 +95,7 @@ public: class renderer_ogl : public osd_renderer { public: - renderer_ogl(std::shared_ptr<osd_window> window) + renderer_ogl(osd_window *window) : osd_renderer(window, FLAG_NEEDS_OPENGL) , m_blittimer(0) , m_width(0) @@ -141,18 +141,14 @@ public: #endif virtual render_primitive_list *get_primitives() override { - auto win = try_getwindow(); - if (win == nullptr) - return nullptr; - - osd_dim nd = win->get_size(); + osd_dim nd = window().get_size(); if (nd != m_blit_dim) { m_blit_dim = nd; notify_changed(); } - win->target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), win->pixel_aspect()); - return &win->target()->get_primitives(); + window().target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), window().pixel_aspect()); + return &window().target()->get_primitives(); } #ifdef OSD_WINDOWS diff --git a/src/osd/modules/render/drawsdl.cpp b/src/osd/modules/render/drawsdl.cpp index 622c360df7e..41853c5e05c 100644 --- a/src/osd/modules/render/drawsdl.cpp +++ b/src/osd/modules/render/drawsdl.cpp @@ -105,10 +105,8 @@ void renderer_sdl1::setup_texture(const osd_dim &size) SDL_DisplayMode mode; UINT32 fmt; - auto win = assert_window(); - // Determine preferred pixelformat and set up yuv if necessary - SDL_GetCurrentDisplayMode(*((UINT64 *)win->monitor()->oshandle()), &mode); + SDL_GetCurrentDisplayMode(*((UINT64 *)window().monitor()->oshandle()), &mode); if (m_yuv_bitmap) { @@ -123,11 +121,11 @@ void renderer_sdl1::setup_texture(const osd_dim &size) int m_hw_scale_width = 0; int m_hw_scale_height = 0; - win->target()->compute_minimum_size(m_hw_scale_width, m_hw_scale_height); - if (win->prescale()) + window().target()->compute_minimum_size(m_hw_scale_width, m_hw_scale_height); + if (window().prescale()) { - m_hw_scale_width *= win->prescale(); - m_hw_scale_height *= win->prescale(); + m_hw_scale_width *= window().prescale(); + m_hw_scale_height *= window().prescale(); /* This must be a multiple of 2 */ m_hw_scale_width = (m_hw_scale_width + 1) & ~1; @@ -187,7 +185,6 @@ int renderer_sdl1::create() { const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; - auto win = assert_window(); // create renderer /* set hints ... */ @@ -195,16 +192,16 @@ int renderer_sdl1::create() if (video_config.waitvsync) - m_sdl_renderer = SDL_CreateRenderer(win->platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); + m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); else - m_sdl_renderer = SDL_CreateRenderer(win->platform_window<SDL_Window*>(), -1, SDL_RENDERER_ACCELERATED); + m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_ACCELERATED); if (!m_sdl_renderer) { if (video_config.waitvsync) - m_sdl_renderer = SDL_CreateRenderer(win->platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_SOFTWARE); + m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_SOFTWARE); else - m_sdl_renderer = SDL_CreateRenderer(win->platform_window<SDL_Window*>(), -1, SDL_RENDERER_SOFTWARE); + m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_SOFTWARE); } if (!m_sdl_renderer) @@ -314,9 +311,7 @@ int renderer_sdl1::draw(int update) return 0; } - auto win = assert_window(); - - osd_dim wdim = win->get_size(); + osd_dim wdim = window().get_size(); if (has_flags(FI_CHANGED) || (wdim != m_last_dim)) { destroy_all_textures(); @@ -383,7 +378,7 @@ int renderer_sdl1::draw(int update) m_last_hofs = hofs; m_last_vofs = vofs; - win->m_primlist->acquire_lock(); + window().m_primlist->acquire_lock(); int mamewidth, mameheight; @@ -401,7 +396,7 @@ int renderer_sdl1::draw(int update) // FIXME: this could be a lot easier if we get the primlist here! // Bounds would be set fit for purpose and done! - for (render_primitive &prim : *win->m_primlist) + for (render_primitive &prim : *window().m_primlist) { prim.bounds.x0 = floor(fw * prim.bounds.x0 + 0.5f); prim.bounds.x1 = floor(fw * prim.bounds.x1 + 0.5f); @@ -415,23 +410,23 @@ int renderer_sdl1::draw(int update) switch (rmask) { case 0x0000ff00: - software_renderer<UINT32, 0,0,0, 8,16,24>::draw_primitives(*win->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); + software_renderer<UINT32, 0,0,0, 8,16,24>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); break; case 0x00ff0000: - software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*win->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); + software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); break; case 0x000000ff: - software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*win->m_primlist, surfptr, mamewidth, mameheight, pitch / 4); + software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 4); break; case 0xf800: - software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*win->m_primlist, surfptr, mamewidth, mameheight, pitch / 2); + software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2); break; case 0x7c00: - software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*win->m_primlist, surfptr, mamewidth, mameheight, pitch / 2); + software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, surfptr, mamewidth, mameheight, pitch / 2); break; default: @@ -443,11 +438,11 @@ int renderer_sdl1::draw(int update) { assert (m_yuv_bitmap != nullptr); assert (surfptr != nullptr); - software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*win->m_primlist, m_yuv_bitmap, mamewidth, mameheight, mamewidth); + software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, m_yuv_bitmap, mamewidth, mameheight, mamewidth); sm->yuv_blit((UINT16 *)m_yuv_bitmap, surfptr, pitch, m_yuv_lookup, mamewidth, mameheight); } - win->m_primlist->release_lock(); + window().m_primlist->release_lock(); // unlock and flip SDL_UnlockTexture(m_texture_id); @@ -676,16 +671,12 @@ static void yuv_RGB_to_YUY2X2(const UINT16 *bitmap, UINT8 *ptr, const int pitch, render_primitive_list *renderer_sdl1::get_primitives() { - auto win = try_getwindow(); - if (win == nullptr) - return nullptr; - - osd_dim nd = win->get_size(); + osd_dim nd = window().get_size(); if (nd != m_blit_dim) { m_blit_dim = nd; notify_changed(); } - win->target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), win->pixel_aspect()); - return &win->target()->get_primitives(); + window().target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), window().pixel_aspect()); + return &window().target()->get_primitives(); } diff --git a/src/osd/modules/render/drawsdl.h b/src/osd/modules/render/drawsdl.h index 4bdceb69ab7..2958dbf265a 100644 --- a/src/osd/modules/render/drawsdl.h +++ b/src/osd/modules/render/drawsdl.h @@ -20,7 +20,7 @@ class renderer_sdl1 : public osd_renderer { public: - renderer_sdl1(std::shared_ptr<osd_window> w, int extra_flags) + renderer_sdl1(osd_window *w, int extra_flags) : osd_renderer(w, FLAG_NEEDS_OPENGL | extra_flags) , m_sdl_renderer(nullptr) , m_texture_id(nullptr) diff --git a/src/osd/modules/sound/direct_sound.cpp b/src/osd/modules/sound/direct_sound.cpp index 25a82146d6b..d00dc41c162 100644 --- a/src/osd/modules/sound/direct_sound.cpp +++ b/src/osd/modules/sound/direct_sound.cpp @@ -404,10 +404,10 @@ HRESULT sound_direct_sound::dsound_init() #ifdef SDLMAME_WIN32 SDL_SysWMinfo wminfo; SDL_VERSION(&wminfo.version); - SDL_GetWindowWMInfo(sdl_window_list.front()->platform_window<SDL_Window*>(), &wminfo); + SDL_GetWindowWMInfo(sdl_window_list->platform_window<SDL_Window*>(), &wminfo); HWND const window = wminfo.info.win.window; #else // SDLMAME_WIN32 - HWND const window = win_window_list.front()->platform_window<HWND>(); + HWND const window = win_window_list->platform_window<HWND>(); #endif // SDLMAME_WIN32 result = m_dsound->SetCooperativeLevel(window, DSSCL_PRIORITY); } diff --git a/src/osd/sdl/video.cpp b/src/osd/sdl/video.cpp index 418df2cbe89..1b346dc686e 100644 --- a/src/osd/sdl/video.cpp +++ b/src/osd/sdl/video.cpp @@ -82,7 +82,7 @@ bool sdl_osd_interface::video_init() get_resolution(options().resolution(), options().resolution(index), &conf, TRUE); // create window ... - std::shared_ptr<sdl_window_info> win = std::make_shared<sdl_window_info>(machine(), index, osd_monitor_info::pick_monitor(reinterpret_cast<osd_options &>(options()), index), &conf); + sdl_window_info *win = global_alloc(sdl_window_info(machine(), index, osd_monitor_info::pick_monitor(reinterpret_cast<osd_options &>(options()), index), &conf)); if (win->window_init()) return false; @@ -140,7 +140,7 @@ void sdl_osd_interface::update(bool skip_redraw) if (!skip_redraw) { // profiler_mark(PROFILER_BLIT); - for (auto window : sdl_window_list) + for (sdl_window_info *window = sdl_window_list; window != NULL; window = window->m_next) window->update(); // profiler_mark(PROFILER_END); } @@ -270,14 +270,20 @@ finishit: static void check_osd_inputs(running_machine &machine) { + sdl_window_info *window = sdl_window_list; + // check for toggling fullscreen mode if (machine.ui_input().pressed(IPT_OSD_1)) { - for (auto curwin : sdl_window_list) + sdl_window_info *curwin = sdl_window_list; + + while (curwin != (sdl_window_info *)NULL) + { curwin->toggle_full_screen(); + curwin = curwin->m_next; + } } - auto window = sdl_window_list.front(); if (machine.ui_input().pressed(IPT_OSD_2)) { //FIXME: on a per window basis diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp index b1bd5cc0396..0fc29529f33 100644 --- a/src/osd/sdl/window.cpp +++ b/src/osd/sdl/window.cpp @@ -23,8 +23,6 @@ #ifndef _MSC_VER #include <unistd.h> #endif -#include <list> -#include <memory> // MAME headers @@ -82,7 +80,14 @@ // GLOBAL VARIABLES //============================================================ -std::list<std::shared_ptr<sdl_window_info>> sdl_window_list; +sdl_window_info *sdl_window_list; + + +//============================================================ +// LOCAL VARIABLES +//============================================================ + +static sdl_window_info **last_window_ptr; class SDL_DM_Wrapper { @@ -99,33 +104,31 @@ static SDL_threadID window_threadid; // debugger //static int in_background; -class worker_param -{ -public: +struct worker_param { worker_param() : m_window(nullptr), m_list(nullptr), m_resize_new_width(0), m_resize_new_height(0) { } - worker_param(std::shared_ptr<sdl_window_info> awindow, render_primitive_list &alist) + worker_param(sdl_window_info *awindow, render_primitive_list &alist) : m_window(awindow), m_list(&alist), m_resize_new_width(0), m_resize_new_height(0) { } - worker_param(std::shared_ptr<sdl_window_info> awindow, int anew_width, int anew_height) + worker_param(sdl_window_info *awindow, int anew_width, int anew_height) : m_window(awindow), m_list(nullptr), m_resize_new_width(anew_width), m_resize_new_height(anew_height) { } - worker_param(std::shared_ptr<sdl_window_info> awindow) + worker_param(sdl_window_info *awindow) : m_window(awindow), m_list(nullptr), m_resize_new_width(0), m_resize_new_height(0) { } - std::shared_ptr<sdl_window_info> window() const { assert(m_window != nullptr); return m_window; } + sdl_window_info *window() const { assert(m_window != nullptr); return m_window; } render_primitive_list *list() const { return m_list; } int new_width() const { return m_resize_new_width; } int new_height() const { return m_resize_new_height; } // FIXME: only needed for window set-up which returns an error. - void set_window(std::shared_ptr<sdl_window_info> window) { m_window = window; } + void set_window(sdl_window_info *window) { m_window = window; } private: - std::shared_ptr<sdl_window_info> m_window; + sdl_window_info *m_window; render_primitive_list *m_list; int m_resize_new_width; int m_resize_new_height; @@ -142,15 +145,20 @@ static void sdlwindow_sync(void); // execute_async //============================================================ -// The idea of using unique_ptr here is to make sure the caller isn't holding onto a copy -static inline void execute_async(osd_work_callback callback, std::unique_ptr<worker_param> wp) + +static inline void execute_async(osd_work_callback callback, const worker_param &wp) { - callback(wp.release(), 0); + worker_param *wp_temp = (worker_param *) osd_malloc(sizeof(worker_param)); + *wp_temp = wp; + callback((void *) wp_temp, 0); } -static inline void execute_sync(osd_work_callback callback, std::unique_ptr<worker_param> wp) +static inline void execute_sync(osd_work_callback callback, const worker_param &wp) { - callback(wp.release(), 0); + worker_param *wp_temp = (worker_param *) osd_malloc(sizeof(worker_param)); + *wp_temp = wp; + + callback((void *) wp_temp, 0); } @@ -158,9 +166,9 @@ static inline void execute_sync(osd_work_callback callback, std::unique_ptr<work // execute_async_wait //============================================================ -static inline void execute_async_wait(osd_work_callback callback, std::unique_ptr<worker_param> wp) +static inline void execute_async_wait(osd_work_callback callback, const worker_param &wp) { - execute_async(callback, std::move(wp)); + execute_async(callback, wp); sdlwindow_sync(); } @@ -246,6 +254,7 @@ bool sdl_osd_interface::window_init() osd_printf_verbose("\t%-40s %s\n", hints[i], SDL_GetHint(hints[i])); // set up the window list + last_window_ptr = &sdl_window_list; osd_printf_verbose("Leave sdlwindow_init\n"); return true; } @@ -263,10 +272,10 @@ static void sdlwindow_sync(void) void sdl_osd_interface::update_slider_list() { - for (auto window : sdl_window_list) + for (sdl_window_info *window = sdl_window_list; window != nullptr; window = window->m_next) { // check if any window has dirty sliders - if (window->renderer().sliders_dirty()) + if (&window->renderer() && window->renderer().sliders_dirty()) { build_slider_list(); return; @@ -278,7 +287,7 @@ void sdl_osd_interface::build_slider_list() { m_sliders.clear(); - for (auto window : sdl_window_list) + for (sdl_window_info *window = sdl_window_list; window != nullptr; window = window->m_next) { std::vector<ui_menu_item> window_sliders = window->renderer().get_slider_list(); m_sliders.insert(m_sliders.end(), window_sliders.begin(), window_sliders.end()); @@ -300,19 +309,20 @@ static OSDWORK_CALLBACK( sdlwindow_exit_wt ) void sdl_osd_interface::window_exit() { - std::unique_ptr<worker_param> wp_dummy(nullptr); + worker_param wp_dummy; ASSERT_MAIN_THREAD(); osd_printf_verbose("Enter sdlwindow_exit\n"); // free all the windows - while (!sdl_window_list.empty()) + while (sdl_window_list != nullptr) { - auto window = sdl_window_list.front(); - - // Part of destroy removes the window from the list - window->destroy(); + sdl_window_info *temp = sdl_window_list; + sdl_window_list = temp->m_next; + temp->destroy(); + // free the window itself + global_free(temp); } switch(video_config.mode) @@ -335,7 +345,7 @@ void sdl_osd_interface::window_exit() break; } - execute_async_wait(&sdlwindow_exit_wt, std::move(wp_dummy)); + execute_async_wait(&sdlwindow_exit_wt, wp_dummy); osd_printf_verbose("Leave sdlwindow_exit\n"); @@ -374,8 +384,8 @@ void sdl_window_info::show_pointer() OSDWORK_CALLBACK( sdl_window_info::sdlwindow_resize_wt ) { - auto wp = std::unique_ptr<worker_param>(static_cast<worker_param*>(param)); - auto window = wp->window(); + worker_param * wp = (worker_param *) param; + sdl_window_info * window = wp->window(); int width = wp->new_width(); int height = wp->new_height(); @@ -384,6 +394,7 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_resize_wt ) SDL_SetWindowSize(window->platform_window<SDL_Window*>(), width, height); window->renderer().notify_changed(); + osd_free(wp); return nullptr; } @@ -394,10 +405,7 @@ void sdl_window_info::resize(INT32 width, INT32 height) osd_dim cd = get_size(); if (width != cd.width() || height != cd.height()) - { - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this()), width, height); - execute_async_wait(&sdlwindow_resize_wt, std::move(wp)); - } + execute_async_wait(&sdlwindow_resize_wt, worker_param(this, width, height)); } @@ -408,24 +416,26 @@ void sdl_window_info::resize(INT32 width, INT32 height) OSDWORK_CALLBACK( sdl_window_info::notify_changed_wt ) { - auto wp = std::unique_ptr<worker_param>(static_cast<worker_param*>(param)); - auto window = wp->window(); + worker_param *wp = (worker_param *) param; + sdl_window_info *window = wp->window(); ASSERT_WINDOW_THREAD(); window->renderer().notify_changed(); + osd_free(wp); return nullptr; } void sdl_window_info::notify_changed() { - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); + worker_param wp; + if (SDL_ThreadID() == main_threadid) { - execute_async_wait(¬ify_changed_wt, std::move(wp)); + execute_async_wait(¬ify_changed_wt, worker_param(this)); } else - execute_sync(¬ify_changed_wt, std::move(wp)); + execute_sync(¬ify_changed_wt, worker_param(this)); } @@ -436,8 +446,8 @@ void sdl_window_info::notify_changed() OSDWORK_CALLBACK( sdl_window_info::sdlwindow_toggle_full_screen_wt ) { - auto wp = std::unique_ptr<worker_param>(static_cast<worker_param*>(param)); - auto window = wp->window(); + worker_param *wp = (worker_param *) param; + sdl_window_info *window = wp->window(); ASSERT_WINDOW_THREAD(); @@ -451,6 +461,12 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_toggle_full_screen_wt ) window->m_windowed_dim = window->get_size(); } + if (window->m_renderer != nullptr) + { + delete window->m_renderer; + window->m_renderer = nullptr; + } + bool is_osx = false; #ifdef SDLMAME_MACOSX // FIXME: This is weird behaviour and certainly a bug in SDL @@ -466,7 +482,7 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_toggle_full_screen_wt ) downcast<sdl_osd_interface &>(window->machine().osd()).release_keys(); - window->set_renderer(osd_renderer::make_for_type(video_config.mode, window->shared_from_this())); + window->set_renderer(osd_renderer::make_for_type(video_config.mode, reinterpret_cast<osd_window *>(window))); // toggle the window mode window->set_fullscreen(!window->fullscreen()); @@ -479,12 +495,13 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_toggle_full_screen_wt ) void sdl_window_info::toggle_full_screen() { ASSERT_MAIN_THREAD(); - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); - execute_async_wait(&sdlwindow_toggle_full_screen_wt, std::move(wp)); + + execute_async_wait(&sdlwindow_toggle_full_screen_wt, worker_param(this)); } void sdl_window_info::modify_prescale(int dir) { + worker_param wp = worker_param(this); int new_prescale = prescale(); if (dir > 0 && prescale() < 3) @@ -496,13 +513,11 @@ void sdl_window_info::modify_prescale(int dir) { if (m_fullscreen && video_config.switchres) { - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); - execute_async_wait(&sdlwindow_video_window_destroy_wt, std::move(wp)); + execute_async_wait(&sdlwindow_video_window_destroy_wt, wp); m_prescale = new_prescale; - wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); - execute_async_wait(&complete_create_wt, std::move(wp)); + execute_async_wait(&complete_create_wt, wp); } else @@ -555,11 +570,12 @@ void sdl_window_info::update_cursor_state() OSDWORK_CALLBACK( sdl_window_info::update_cursor_state_wt ) { - auto wp = std::unique_ptr<worker_param>(static_cast<worker_param*>(param)); - auto window = wp->window(); + worker_param * wp = (worker_param *) param; + sdl_window_info * window = wp->window(); window->update_cursor_state(); + osd_free(wp); return nullptr; } @@ -575,6 +591,7 @@ int sdl_window_info::xy_to_render_target(int x, int y, int *xt, int *yt) int sdl_window_info::window_init() { + worker_param *wp = (worker_param *) osd_malloc(sizeof(worker_param)); int result; ASSERT_MAIN_THREAD(); @@ -585,9 +602,10 @@ int sdl_window_info::window_init() m_startmaximized = options.maximize(); // add us to the list - sdl_window_list.push_back(std::static_pointer_cast<sdl_window_info>(shared_from_this())); + *last_window_ptr = this; + last_window_ptr = &this->m_next; - set_renderer(osd_renderer::make_for_type(video_config.mode, static_cast<osd_window*>(this)->shared_from_this())); + set_renderer(osd_renderer::make_for_type(video_config.mode, reinterpret_cast<osd_window *>(this))); // load the layout m_target = m_machine.render().target_alloc(); @@ -601,9 +619,9 @@ int sdl_window_info::window_init() else sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name, m_index); - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); + wp->set_window(this); - result = *((int *) sdl_window_info::complete_create_wt(wp.release(), 0)); + result = *((int *) sdl_window_info::complete_create_wt((void *) wp, 0)); // handle error conditions if (result == 1) @@ -624,11 +642,15 @@ error: OSDWORK_CALLBACK( sdl_window_info::sdlwindow_video_window_destroy_wt ) { - auto wp = std::unique_ptr<worker_param>(static_cast<worker_param*>(param)); - auto window = wp->window(); + worker_param * wp = (worker_param *) param; + sdl_window_info * window = wp->window(); ASSERT_WINDOW_THREAD(); + // free the textures etc + global_free(window->m_renderer); + window->m_renderer = nullptr; + if (window->fullscreen() && video_config.switchres) { SDL_SetWindowFullscreen(window->platform_window<SDL_Window*>(), 0); // Try to set mode @@ -639,21 +661,28 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_video_window_destroy_wt ) // release all keys ... downcast<sdl_osd_interface &>(window->machine().osd()).release_keys(); + osd_free(wp); return nullptr; } void sdl_window_info::destroy() { + sdl_window_info **prevptr; + ASSERT_MAIN_THREAD(); //osd_event_wait(window->rendered_event, osd_ticks_per_second()*10); // remove us from the list - sdl_window_list.remove(std::static_pointer_cast<sdl_window_info>(shared_from_this())); + for (prevptr = &sdl_window_list; *prevptr != nullptr; prevptr = &(*prevptr)->m_next) + if (*prevptr == this) + { + *prevptr = this->m_next; + break; + } // free the textures etc - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); - execute_async_wait(&sdlwindow_video_window_destroy_wt, std::move(wp)); + execute_async_wait(&sdlwindow_video_window_destroy_wt, worker_param(this)); // free the render target, after the textures! this->machine().render().target_free(m_target); @@ -747,8 +776,7 @@ void sdl_window_info::update() // adjust the cursor state //sdlwindow_update_cursor_state(machine, window); - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this())); - execute_async(&update_cursor_state_wt, std::move(wp)); + execute_async(&update_cursor_state_wt, worker_param(this)); // if we're visible and running and not in the middle of a resize, draw if (m_target != nullptr) @@ -782,11 +810,11 @@ void sdl_window_info::update() { // ensure the target bounds are up-to-date, and then get the primitives - render_primitive_list &primlist = *renderer().get_primitives(); + render_primitive_list &primlist = *m_renderer->get_primitives(); // and redraw now - auto wp = std::make_unique<worker_param>(std::static_pointer_cast<sdl_window_info>(shared_from_this()), primlist); - execute_async(&draw_video_contents_wt, std::move(wp)); + + execute_async(&draw_video_contents_wt, worker_param(this, primlist)); } } } @@ -822,13 +850,14 @@ void sdl_window_info::set_starting_view(int index, const char *defview, const ch OSDWORK_CALLBACK( sdl_window_info::complete_create_wt ) { - auto wp = std::unique_ptr<worker_param>(static_cast<worker_param*>(param)); - auto window = wp->window(); + worker_param * wp = (worker_param *) param; + sdl_window_info * window = wp->window(); osd_dim temp(0,0); static int result[2] = {0,1}; ASSERT_WINDOW_THREAD(); + osd_free(wp); // clear out original mode. Needed on OSX if (window->fullscreen()) @@ -952,19 +981,14 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt ) // set main window if (window->m_index > 0) { - for (auto w : sdl_window_list) + for (auto w = sdl_window_list; w != nullptr; w = w->m_next) { if (w->m_index == 0) - { - window->set_main_window(std::dynamic_pointer_cast<osd_window>(w)); + { + window->m_main = w; break; - } - } } - else - { - // We must be the main window - window->set_main_window(window); + } } // update monitor resolution after mode change to ensure proper pixel aspect @@ -1034,8 +1058,8 @@ void sdl_window_info::measure_fps(int update) OSDWORK_CALLBACK( sdl_window_info::draw_video_contents_wt ) { int update = 1; - auto wp = std::unique_ptr<worker_param>(static_cast<worker_param*>(param)); - auto window = wp->window(); + worker_param *wp = (worker_param *) param; + sdl_window_info *window = wp->window(); ASSERT_REDRAW_THREAD(); @@ -1072,6 +1096,7 @@ OSDWORK_CALLBACK( sdl_window_info::draw_video_contents_wt ) /* all done, ready for next */ window->m_rendered_event.set(); + osd_free(wp); return nullptr; } @@ -1338,5 +1363,6 @@ sdl_window_info::sdl_window_info(running_machine &a_machine, int index, osd_moni sdl_window_info::~sdl_window_info() { + global_free(m_renderer); global_free(m_original_mode); } diff --git a/src/osd/sdl/window.h b/src/osd/sdl/window.h index 403c12a8e46..14ee6e3c19a 100644 --- a/src/osd/sdl/window.h +++ b/src/osd/sdl/window.h @@ -17,8 +17,6 @@ #include "modules/osdwindow.h" #include <cstdint> -#include <memory> -#include <list> //============================================================ @@ -67,6 +65,7 @@ public: render_target *target() override { return m_target; } int prescale() const { return m_prescale; } + osd_renderer &renderer() const { return *m_renderer; } // Pointer to next window sdl_window_info * m_next; @@ -89,6 +88,11 @@ private: int m_extra_flags; + void set_renderer(osd_renderer *renderer) + { + m_renderer = renderer; + } + static OSDWORK_CALLBACK( complete_create_wt ); private: @@ -107,6 +111,7 @@ private: // monitor info osd_monitor_info * m_monitor; int m_fullscreen; + osd_renderer * m_renderer; // static callbacks ... @@ -131,7 +136,7 @@ struct osd_draw_callbacks //============================================================ // window - list -extern std::list<std::shared_ptr<sdl_window_info>> sdl_window_list; +extern sdl_window_info *sdl_window_list; //============================================================ // PROTOTYPES diff --git a/src/osd/windows/video.cpp b/src/osd/windows/video.cpp index fc6f787b698..6489c236670 100644 --- a/src/osd/windows/video.cpp +++ b/src/osd/windows/video.cpp @@ -80,7 +80,7 @@ bool windows_osd_interface::video_init() } if (video_config.mode != VIDEO_MODE_NONE) - SetForegroundWindow(win_window_list.front()->platform_window<HWND>()); + SetForegroundWindow(win_window_list->platform_window<HWND>()); return true; } @@ -169,7 +169,7 @@ void windows_osd_interface::update(bool skip_redraw) if (!skip_redraw) { // profiler_mark(PROFILER_BLIT); - for (auto window : win_window_list) + for (win_window_info *window = win_window_list; window != NULL; window = window->m_next) window->update(); // profiler_mark(PROFILER_END); } diff --git a/src/osd/windows/window.cpp b/src/osd/windows/window.cpp index 3f3e84b004c..82d509d6a52 100644 --- a/src/osd/windows/window.cpp +++ b/src/osd/windows/window.cpp @@ -17,8 +17,6 @@ #include <atomic> #include <chrono> -#include <list> -#include <memory> // MAME headers #include "emu.h" @@ -89,7 +87,8 @@ using namespace Windows::UI::Core; // GLOBAL VARIABLES //============================================================ -std::list<std::shared_ptr<win_window_info>> win_window_list; +win_window_info *win_window_list; +static win_window_info **last_window_ptr; static DWORD main_threadid; // actual physical resolution @@ -251,12 +250,15 @@ bool windows_osd_interface::window_init() } video_config.mode = current_mode; + // set up the window list + last_window_ptr = &win_window_list; + return true; } void windows_osd_interface::update_slider_list() { - for (auto window : win_window_list) + for (win_window_info *window = win_window_list; window != nullptr; window = window->m_next) { // check if any window has dirty sliders if (window->m_renderer && window->m_renderer->sliders_dirty()) @@ -269,14 +271,19 @@ void windows_osd_interface::update_slider_list() int windows_osd_interface::window_count() { - return win_window_list.size(); + int count = 0; + for (win_window_info *info = win_window_list; info != nullptr; info = info->m_next) + { + count++; + } + return count; } void windows_osd_interface::build_slider_list() { m_sliders.clear(); - for (auto window : win_window_list) + for (win_window_info *window = win_window_list; window != nullptr; window = window->m_next) { // take the sliders of the first window std::vector<ui_menu_item> window_sliders = window->m_renderer->get_slider_list(); @@ -286,7 +293,7 @@ void windows_osd_interface::build_slider_list() void windows_osd_interface::add_audio_to_recording(const INT16 *buffer, int samples_this_frame) { - auto window = win_window_list.front(); // We only record on the first window + win_window_info *window = win_window_list; // We only record on the first window if (window != nullptr && window->m_renderer != nullptr) { window->m_renderer->add_audio_to_recording(buffer, samples_this_frame); @@ -303,16 +310,15 @@ void windows_osd_interface::window_exit() assert(GetCurrentThreadId() == main_threadid); // if we hid the cursor during the emulation, show it - if (!win_window_list.empty()) - win_window_list.front()->show_pointer(); + win_window_list->show_pointer(); // free all the windows - while (!win_window_list.empty()) + while (win_window_list != nullptr) { - auto window = win_window_list.front(); - - // Destroy removes it from the list also - window->destroy(); + win_window_info *temp = win_window_list; + win_window_list = temp->m_next; + temp->destroy(); + global_free(temp); } switch(video_config.mode) @@ -347,18 +353,14 @@ void windows_osd_interface::window_exit() CloseHandle(window_thread_ready_event); } -win_window_info::win_window_info( - running_machine &machine, - int index, - osd_monitor_info *monitor, - const osd_window_config *config) : osd_window(), - m_next(nullptr), +win_window_info::win_window_info(running_machine &machine) + : osd_window(), m_next(nullptr), m_init_state(0), m_startmaximized(0), m_isminimized(0), m_ismaximized(0), - m_monitor(monitor), - //m_fullscreen(0), + m_monitor(nullptr), + m_fullscreen(0), m_fullscreen_safe(0), m_aspect(0), m_target(nullptr), @@ -376,12 +378,14 @@ win_window_info::win_window_info( m_non_fullscreen_bounds.right = 0; m_non_fullscreen_bounds.bottom = 0; m_prescale = video_config.prescale; - - } win_window_info::~win_window_info() { + if (m_renderer != nullptr) + { + delete m_renderer; + } } POINT win_window_info::s_saved_cursor_pos = { -1, -1 }; @@ -476,7 +480,7 @@ void winwindow_process_events_periodic(running_machine &machine) static BOOL is_mame_window(HWND hwnd) { - for (auto window : win_window_list) + for (win_window_info *window = win_window_list; window != nullptr; window = window->m_next) if (window->platform_window<HWND>() == hwnd) return TRUE; @@ -651,10 +655,12 @@ void winwindow_dispatch_message(running_machine &machine, MSG *message) void winwindow_take_snap(void) { + win_window_info *window; + assert(GetCurrentThreadId() == main_threadid); // iterate over windows and request a snap - for (auto window : win_window_list) + for (window = win_window_list; window != nullptr; window = window->m_next) { window->m_renderer->save(); } @@ -669,10 +675,12 @@ void winwindow_take_snap(void) void winwindow_toggle_fsfx(void) { + win_window_info *window; + assert(GetCurrentThreadId() == main_threadid); // iterate over windows and request a snap - for (auto window : win_window_list) + for (window = win_window_list; window != nullptr; window = window->m_next) { window->m_renderer->toggle_fsfx(); } @@ -687,10 +695,12 @@ void winwindow_toggle_fsfx(void) void winwindow_take_video(void) { + win_window_info *window; + assert(GetCurrentThreadId() == main_threadid); // iterate over windows and request a snap - for (auto window : win_window_list) + for (window = win_window_list; window != nullptr; window = window->m_next) { window->m_renderer->record(); } @@ -705,10 +715,12 @@ void winwindow_take_video(void) void winwindow_toggle_full_screen(void) { + win_window_info *window; + assert(GetCurrentThreadId() == main_threadid); // if we are in debug mode, never go full screen - for (auto window : win_window_list) + for (window = win_window_list; window != nullptr; window = window->m_next) if (window->machine().debug_flags & DEBUG_FLAG_OSD_ENABLED) return; @@ -716,11 +728,9 @@ void winwindow_toggle_full_screen(void) video_config.windowed = !video_config.windowed; // iterate over windows and toggle their fullscreen state - for (auto window : win_window_list) + for (window = win_window_list; window != nullptr; window = window->m_next) SendMessage(window->platform_window<HWND>(), WM_USER_SET_FULLSCREEN, !video_config.windowed, 0); - - // Set the first window as foreground - SetForegroundWindow(win_window_list.front()->platform_window<HWND>()); + SetForegroundWindow(win_window_list->platform_window<HWND>()); } @@ -733,9 +743,10 @@ void winwindow_toggle_full_screen(void) BOOL winwindow_has_focus(void) { HWND focuswnd = GetFocus(); + win_window_info *window; // see if one of the video windows has focus - for (auto window : win_window_list) + for (window = win_window_list; window != nullptr; window = window->m_next) if (focuswnd == window->platform_window<HWND>()) return TRUE; @@ -752,21 +763,19 @@ void winwindow_update_cursor_state(running_machine &machine) { assert(GetCurrentThreadId() == main_threadid); - // If no windows, just return - if (win_window_list.empty()) + win_window_info *window = win_window_list; + + // If no window yet, just return + if (window == nullptr) return; - auto window = win_window_list.front(); - // if we should hide the mouse cursor, then do it // rules are: // 1. we must have focus before hiding the cursor // 2. we also hide the cursor in full screen mode and when tshe window doesn't have a menu // 3. we also hide the cursor in windowed mode if we're not paused and // the input system requests it - if (winwindow_has_focus() && ( - (window->fullscreen() && !window->win_has_menu()) - || (!machine.paused() && WINOSD(machine)->should_hide_mouse()))) + if (winwindow_has_focus() && ((!video_config.windowed && !window->win_has_menu()) || (!machine.paused() && downcast<windows_osd_interface&>(machine.osd()).should_hide_mouse()))) { // hide cursor window->hide_pointer(); @@ -793,37 +802,44 @@ void winwindow_update_cursor_state(running_machine &machine) void win_window_info::create(running_machine &machine, int index, osd_monitor_info *monitor, const osd_window_config *config) { + win_window_info *win; + assert(GetCurrentThreadId() == main_threadid); // allocate a new window object - auto window = std::make_shared<win_window_info>(machine, index, monitor, config); + win_window_info *window = global_alloc(win_window_info(machine)); + window->m_win_config = *config; + window->m_monitor = monitor; + window->m_fullscreen = !video_config.windowed; + window->m_index = index; // set main window - if (window->m_index > 0) + if (index > 0) { - for (auto w : win_window_list) + for (auto w = win_window_list; w != nullptr; w = w->m_next) { if (w->m_index == 0) { - window->set_main_window(std::dynamic_pointer_cast<osd_window>(w)); + window->m_main = w; break; } } } else { - // We must be the main window - window->set_main_window(window); + // Give the main window a reference to itself + window->m_main = window; } // see if we are safe for fullscreen window->m_fullscreen_safe = TRUE; - for (auto win : win_window_list) + for (win = win_window_list; win != nullptr; win = win->m_next) if (win->m_monitor == monitor) window->m_fullscreen_safe = FALSE; // add us to the list - win_window_list.push_back(window); + *last_window_ptr = window; + last_window_ptr = &window->m_next; // load the layout window->m_target = machine.render().target_alloc(); @@ -864,10 +880,17 @@ void win_window_info::create(running_machine &machine, int index, osd_monitor_in void win_window_info::destroy() { + win_window_info **prevptr; + assert(GetCurrentThreadId() == main_threadid); // remove us from the list - win_window_list.remove(std::static_pointer_cast<win_window_info>(shared_from_this())); + for (prevptr = &win_window_list; *prevptr != nullptr; prevptr = &(*prevptr)->m_next) + if (*prevptr == this) + { + *prevptr = this->m_next; + break; + } // destroy the window if (platform_window<HWND>() != nullptr) @@ -904,7 +927,7 @@ void win_window_info::update() m_targetlayerconfig = targetlayerconfig; // in window mode, reminimize/maximize - if (!fullscreen()) + if (!m_fullscreen) { if (m_isminimized) SendMessage(platform_window<HWND>(), WM_USER_SET_MINSIZE, 0, 0); @@ -962,7 +985,7 @@ osd_monitor_info *win_window_info::winwindow_video_window_monitor(const osd_rect osd_monitor_info *monitor; // in window mode, find the nearest - if (!fullscreen()) + if (!m_fullscreen) { if (proposed != nullptr) { @@ -1136,7 +1159,7 @@ int winwindow_ui_is_paused(running_machine &machine) int win_window_info::wnd_extra_width() { RECT temprect = { 100, 100, 200, 200 }; - if (fullscreen()) + if (m_fullscreen) return 0; AdjustWindowRectEx(&temprect, WINDOW_STYLE, win_has_menu(), WINDOW_STYLE_EX); return rect_width(&temprect) - 100; @@ -1152,7 +1175,7 @@ int win_window_info::wnd_extra_width() int win_window_info::wnd_extra_height() { RECT temprect = { 100, 100, 200, 200 }; - if (fullscreen()) + if (m_fullscreen) return 0; AdjustWindowRectEx(&temprect, WINDOW_STYLE, win_has_menu(), WINDOW_STYLE_EX); return rect_height(&temprect) - 100; @@ -1281,10 +1304,10 @@ int win_window_info::complete_create() // create the window, but don't show it yet HWND hwnd = win_create_window_ex_utf8( - fullscreen() ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX, + m_fullscreen ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX, "MAME", m_title, - fullscreen() ? FULLSCREEN_STYLE : WINDOW_STYLE, + m_fullscreen ? FULLSCREEN_STYLE : WINDOW_STYLE, monitorbounds.left() + 20, monitorbounds.top() + 20, monitorbounds.left() + 100, monitorbounds.top() + 100, nullptr,//(win_window_list != nullptr) ? win_window_list->m_hwnd : nullptr, @@ -1320,9 +1343,14 @@ int win_window_info::complete_create() adjust_window_position_after_major_change(); // show the window - if (!fullscreen() || m_fullscreen_safe) + if (!m_fullscreen || m_fullscreen_safe) { - m_renderer = osd_renderer::make_for_type(video_config.mode, std::static_pointer_cast<win_window_info>(shared_from_this())); + // finish off by trying to initialize DirectX; if we fail, ignore it + if (m_renderer != nullptr) + { + delete m_renderer; + } + m_renderer = osd_renderer::make_for_type(video_config.mode, reinterpret_cast<osd_window *>(this)); if (m_renderer->create()) return 1; @@ -1373,7 +1401,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR // non-client paint: punt if full screen case WM_NCPAINT: - if (!window->fullscreen() || window->win_has_menu()) + if (!window->m_fullscreen || window->win_has_menu()) return DefWindowProc(wnd, message, wparam, lparam); break; @@ -1519,7 +1547,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR // destroy: clean up all attached rendering bits and nullptr out our hwnd case WM_DESTROY: - window->m_renderer.reset(); + global_free(window->m_renderer); + window->m_renderer = nullptr; window->set_platform_window(nullptr); return DefWindowProc(wnd, message, wparam, lparam); @@ -1689,7 +1718,7 @@ osd_rect win_window_info::constrain_to_aspect_ratio(const osd_rect &rect, int ad propheight = MAX(propheight, minheight); // clamp against the maximum (fit on one screen for full screen mode) - if (fullscreen()) + if (m_fullscreen) { maxwidth = monitor->position_size().width() - extrawidth; maxheight = monitor->position_size().height() - extraheight; @@ -1849,7 +1878,7 @@ void win_window_info::update_minmax_state() { assert(GetCurrentThreadId() == window_threadid); - if (!fullscreen()) + if (!m_fullscreen) { RECT bounds; @@ -1934,7 +1963,7 @@ void win_window_info::adjust_window_position_after_major_change() osd_rect newrect = RECT_to_osd_rect(oldrect); // adjust the window size so the client area is what we want - if (!fullscreen()) + if (!m_fullscreen) { // constrain the existing size to the aspect ratio if (video_config.keepaspect) @@ -1951,12 +1980,12 @@ void win_window_info::adjust_window_position_after_major_change() // adjust the position if different if (oldrect.left != newrect.left() || oldrect.top != newrect.top() || oldrect.right != newrect.right() || oldrect.bottom != newrect.bottom()) - SetWindowPos(platform_window<HWND>(), fullscreen() ? HWND_TOPMOST : HWND_TOP, + SetWindowPos(platform_window<HWND>(), m_fullscreen ? HWND_TOPMOST : HWND_TOP, newrect.left(), newrect.top(), newrect.width(), newrect.height(), 0); // take note of physical window size (used for lightgun coordinate calculation) - if (m_index == 0) + if (this == win_window_list) { win_physical_width = newrect.width(); win_physical_height = newrect.height(); @@ -1975,12 +2004,13 @@ void win_window_info::set_fullscreen(int fullscreen) assert(GetCurrentThreadId() == window_threadid); // if we're in the right state, punt - if (this->fullscreen() == fullscreen) + if (m_fullscreen == fullscreen) return; - video_config.windowed = !fullscreen; + m_fullscreen = fullscreen; // kill off the drawers - m_renderer.reset(); + delete m_renderer; + m_renderer = nullptr; // hide ourself ShowWindow(platform_window<HWND>(), SW_HIDE); @@ -2032,12 +2062,12 @@ void win_window_info::set_fullscreen(int fullscreen) adjust_window_position_after_major_change(); // show ourself - if (!this->fullscreen() || m_fullscreen_safe) + if (!m_fullscreen || m_fullscreen_safe) { if (video_config.mode != VIDEO_MODE_NONE) ShowWindow(platform_window<HWND>(), SW_SHOW); - m_renderer = osd_renderer::make_for_type(video_config.mode, std::static_pointer_cast<win_window_info>(shared_from_this())); + m_renderer = reinterpret_cast<osd_renderer *>(osd_renderer::make_for_type(video_config.mode, reinterpret_cast<osd_window *>(this))); if (m_renderer->create()) exit(1); } diff --git a/src/osd/windows/window.h b/src/osd/windows/window.h index 47eae45d034..a8d1fbffdb6 100644 --- a/src/osd/windows/window.h +++ b/src/osd/windows/window.h @@ -17,9 +17,6 @@ #include <chrono> #include <mutex> -#include <memory> -#include <list> - #include "video.h" #include "render.h" @@ -47,13 +44,13 @@ class win_window_info : public osd_window { public: - win_window_info(running_machine &machine, int index, osd_monitor_info *monitor, const osd_window_config *config); + win_window_info(running_machine &machine); virtual ~win_window_info(); running_machine &machine() const override { return m_machine; } virtual render_target *target() override { return m_target; } - int fullscreen() const override { return !video_config.windowed; } + int fullscreen() const override { return m_fullscreen; } void update(); @@ -111,7 +108,7 @@ public: // monitor info osd_monitor_info * m_monitor; - //int m_fullscreen; + int m_fullscreen; int m_fullscreen_safe; float m_aspect; @@ -128,7 +125,7 @@ public: int m_lastclicky; // drawing data - std::unique_ptr<osd_renderer> m_renderer; + osd_renderer * m_renderer; private: void draw_video_contents(HDC dc, int update); @@ -165,7 +162,7 @@ struct osd_draw_callbacks //============================================================ // windows -extern std::list<std::shared_ptr<win_window_info>> win_window_list; +extern win_window_info *win_window_list; diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp index 136daea0636..e4672c4fafb 100644 --- a/src/osd/windows/winmain.cpp +++ b/src/osd/windows/winmain.cpp @@ -68,11 +68,11 @@ public: char buffer[1024]; // if we are in fullscreen mode, go to windowed mode - if ((video_config.windowed == 0) && !win_window_list.empty()) + if ((video_config.windowed == 0) && (win_window_list != nullptr)) winwindow_toggle_full_screen(); vsnprintf(buffer, ARRAY_LENGTH(buffer), msg, args); - win_message_box_utf8(!win_window_list.empty() ? win_window_list.front()->platform_window<HWND>() : nullptr, buffer, emulator_info::get_appname(), MB_OK); + win_message_box_utf8(win_window_list ? win_window_list->platform_window<HWND>() : nullptr, buffer, emulator_info::get_appname(), MB_OK); } else chain_output(channel, msg, args); @@ -512,7 +512,7 @@ void windows_osd_interface::init(running_machine &machine) osd_common_t::init_subsystems(); // notify listeners of screen configuration - for (auto info : win_window_list) + for (win_window_info *info = win_window_list; info != nullptr; info = info->m_next) { machine.output().set_value(string_format("Orientation(%s)", info->m_monitor->devicename()).c_str(), info->m_targetorient); } |