From fa1c2c483d6bc69b86571d9e2e437e8f8a131a6b Mon Sep 17 00:00:00 2001 From: Jeremy Hayes Date: Wed, 11 Jun 2014 11:36:58 -0600 Subject: [PATCH] Use SDL for replay. --- qtcreator/CMakeLists.txt | 1 + src/voglbench/CMakeLists.txt | 1 - src/voglbench/voglbench.cpp | 348 -------------------- src/voglcommon/vogl_gl_replayer.cpp | 78 +---- src/voglcommon/vogl_replay_window.cpp | 167 +--------- src/voglcommon/vogl_replay_window.h | 41 +-- src/voglcore/vogl_build_options.h | 2 +- src/vogleditor/CMakeLists.txt | 8 +- src/vogleditor/vogleditor_tracereplayer.cpp | 82 +++-- src/vogleditor/vogleditor_tracereplayer.h | 2 +- src/voglreplay/replay_tool_replay.cpp | 293 +++++++--------- src/voglreplay/vogl_replay_tool.cpp | 31 +- 12 files changed, 194 insertions(+), 860 deletions(-) diff --git a/qtcreator/CMakeLists.txt b/qtcreator/CMakeLists.txt index 61f07f30..66206c05 100644 --- a/qtcreator/CMakeLists.txt +++ b/qtcreator/CMakeLists.txt @@ -29,6 +29,7 @@ add_definitions("-DVOGL_USE_LINUX_API=1") add_definitions("-DSDL_VIDEO_OPENGL_GLX=1") add_definitions("-DSDL_VIDEO_DRIVER_X11=1") add_definitions("-DSDL_VIDEO_DRIVER_X11_DYNAMIC=1") +add_definitions("-DVOGL_PLATFORM_HAS_SDL=1") add_definitions("-DVOGL_PLATFORM_HAS_X11=1") add_definitions("-DVOGL_PLATFORM_HAS_GLX=1") add_definitions("-DPLATFORM_POSIX=1") diff --git a/src/voglbench/CMakeLists.txt b/src/voglbench/CMakeLists.txt index a239f91e..5c560e0b 100644 --- a/src/voglbench/CMakeLists.txt +++ b/src/voglbench/CMakeLists.txt @@ -39,4 +39,3 @@ target_link_libraries(${PROJECT_NAME} ) build_options_finalize() - diff --git a/src/voglbench/voglbench.cpp b/src/voglbench/voglbench.cpp index b5cda259..1a957419 100644 --- a/src/voglbench/voglbench.cpp +++ b/src/voglbench/voglbench.cpp @@ -51,12 +51,6 @@ #include "SDL.h" #endif -#if defined(PLATFORM_POSIX) - #include - #include - #include -#endif - //$ TODO: investigate using SDL for windows and any keyboard controls. //$ Run clang-format on everything. //$ Use Telemetry to speed this bugger up. @@ -313,41 +307,6 @@ static void voglbench_deinit() colorized_console::deinit(); } -#if VOGL_PLATFORM_HAS_X11 - //---------------------------------------------------------------------------------------------------------------------- - // X11_Pending - from SDL - //---------------------------------------------------------------------------------------------------------------------- - static int X11_Pending(Display *display) - { - VOGL_FUNC_TRACER - - /* Flush the display connection and look to see if events are queued */ - XFlush(display); - if (XEventsQueued(display, QueuedAlready)) - { - return 1; - } - - /* More drastic measures are required -- see if X is ready to talk */ - { - static struct timeval zero_time; /* static == 0 */ - int x11_fd; - fd_set fdset; - - x11_fd = ConnectionNumber(display); - FD_ZERO(&fdset); - FD_SET(x11_fd, &fdset); - if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) - { - return (XPending(display)); - } - } - - /* Oh well, nothing is ready .. */ - return 0; - } -#endif - //---------------------------------------------------------------------------------------------------------------------- // get_replayer_flags_from_command_line_params //---------------------------------------------------------------------------------------------------------------------- @@ -619,309 +578,6 @@ static uint get_replayer_flags_from_command_line_params() error_exit: return false; } - -#elif (VOGL_PLATFORM_HAS_X11) - //---------------------------------------------------------------------------------------------------------------------- - // tool_replay_mode - //---------------------------------------------------------------------------------------------------------------------- - static bool tool_replay_mode() - { - VOGL_FUNC_TRACER - - dynamic_string trace_filename(g_command_line_params().get_value_as_string_or_empty("", 1)); - if (trace_filename.is_empty()) - { - vogl_error_printf("No trace file specified!\n"); - return false; - } - - dynamic_string actual_trace_filename; - vogl_unique_ptr pTrace_reader(vogl_open_trace_file( - trace_filename, - actual_trace_filename, - g_command_line_params().get_value_as_string_or_empty("loose_file_path").get_ptr())); - if (!pTrace_reader.get()) - { - vogl_error_printf("File not found, or unable to determine file type of trace file \"%s\"\n", trace_filename.get_ptr()); - return false; - } - - vogl_printf("Reading trace file %s\n", actual_trace_filename.get_ptr()); - - vogl_gl_replayer replayer; - vogl_replay_window window; - - uint replayer_flags = get_replayer_flags_from_command_line_params(); - - // TODO: This will create a window with default attributes, which seems fine for the majority of traces. - // Unfortunately, some GL call streams *don't* want an alpha channel, or depth, or stencil etc. in the default framebuffer so this may become a problem. - // Also, this design only supports a single window, which is going to be a problem with multiple window traces. - if (!window.open(g_command_line_params().get_value_as_int("width", 0, 1024, 1, 65535), g_command_line_params().get_value_as_int("height", 0, 768, 1, 65535), g_command_line_params().get_value_as_int("msaa", 0, 0, 0, 65535))) - { - vogl_error_printf("Failed initializing replay window\n"); - return false; - } - - if (!replayer.init(replayer_flags, &window, pTrace_reader->get_sof_packet(), pTrace_reader->get_multi_blob_manager())) - { - vogl_error_printf("Failed initializing GL replayer\n"); - return false; - } - - // Disable all glGetError() calls in vogl_utils.cpp. - vogl_disable_gl_get_error(); - - XSelectInput(window.get_display(), window.get_xwindow(), - EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | KeymapStateMask); - - Atom wmDeleteMessage = XInternAtom(window.get_display(), "WM_DELETE_WINDOW", False); - XSetWMProtocols(window.get_display(), window.get_xwindow(), &wmDeleteMessage, 1); - - // Bool win_mapped = false; - - vogl_gl_state_snapshot *pSnapshot = NULL; - int64_t snapshot_loop_start_frame = -1; - int64_t snapshot_loop_end_frame = -1; - - vogl::hash_map keys_pressed, keys_down; - - int loop_frame = g_command_line_params().get_value_as_int("loop_frame", 0, -1); - int loop_len = math::maximum(g_command_line_params().get_value_as_int("loop_len", 0, 1), 1); - int loop_count = math::maximum(g_command_line_params().get_value_as_int("loop_count", 0, cINT32_MAX), 1); - bool endless_mode = g_command_line_params().get_value_as_bool("endless"); - - timer tm; - tm.start(); - - for (;;) - { - tmZone(TELEMETRY_LEVEL0, TMZF_NONE, "Main Loop"); - - while (X11_Pending(window.get_display())) - { - XEvent newEvent; - - // Watch for new X eventsn - XNextEvent(window.get_display(), &newEvent); - - switch (newEvent.type) - { - case KeyPress: - { - KeySym xsym = XLookupKeysym(&newEvent.xkey, 0); - - //printf("KeyPress 0%04llX %" PRIu64 "\n", (uint64_t)xsym, (uint64_t)xsym); - - keys_down.insert(xsym); - keys_pressed.insert(xsym); - - break; - } - case KeyRelease: - { - KeySym xsym = XLookupKeysym(&newEvent.xkey, 0); - - //printf("KeyRelease 0x%04llX %" PRIu64 "\n", (uint64_t)xsym, (uint64_t)xsym); - - keys_down.erase(xsym); - - break; - } - case FocusIn: - case FocusOut: - { - //printf("FocusIn/FocusOut\n"); - - keys_down.reset(); - - break; - } - case MappingNotify: - { - //XRefreshKeyboardMapping(&newEvent); - break; - } - case UnmapNotify: - { - // printf("UnmapNotify\n"); - // win_mapped = false; - - keys_down.reset(); - - break; - } - case MapNotify: - { - // printf("MapNotify\n"); - // win_mapped = true; - - keys_down.reset(); - - if (!replayer.update_window_dimensions()) - goto error_exit; - - break; - } - case ConfigureNotify: - { - if (!replayer.update_window_dimensions()) - goto error_exit; - - break; - } - case DestroyNotify: - { - vogl_message_printf("Exiting\n"); - goto normal_exit; - } - case ClientMessage: - { - if (newEvent.xclient.data.l[0] == (int)wmDeleteMessage) - { - vogl_message_printf("Exiting\n"); - goto normal_exit; - } - - break; - } - default: - break; - } - } - - if (replayer.get_at_frame_boundary()) - { - if ((!pSnapshot) && (loop_frame != -1) && (static_cast(replayer.get_frame_index()) == loop_frame)) - { - vogl_debug_printf("Capturing replayer state at start of frame %u\n", replayer.get_frame_index()); - - pSnapshot = replayer.snapshot_state(); - - if (pSnapshot) - { - vogl_printf("Snapshot succeeded\n"); - - snapshot_loop_start_frame = pTrace_reader->get_cur_frame(); - snapshot_loop_end_frame = pTrace_reader->get_cur_frame() + loop_len; - - vogl_debug_printf("Loop start: %" PRIi64 " Loop end: %" PRIi64 "\n", snapshot_loop_start_frame, snapshot_loop_end_frame); - } - else - { - vogl_error_printf("Snapshot failed!\n"); - loop_frame = -1; - } - } - } - - vogl_gl_replayer::status_t status = replayer.process_pending_window_resize(); - if (status == vogl_gl_replayer::cStatusOK) - { - for (;;) - { - if (replayer.has_pending_packets()) - { - status = replayer.process_pending_packets(); - } - else - { - status = replayer.process_next_packet(*pTrace_reader); - } - - if ((status == vogl_gl_replayer::cStatusNextFrame) || - (status == vogl_gl_replayer::cStatusResizeWindow) || - (status == vogl_gl_replayer::cStatusAtEOF) || - (status == vogl_gl_replayer::cStatusHardFailure)) - { - break; - } - } - } - - if (status == vogl_gl_replayer::cStatusHardFailure) - break; - - if (status == vogl_gl_replayer::cStatusAtEOF) - { - vogl_message_printf("At trace EOF, frame index %u\n", replayer.get_frame_index()); - } - - if (replayer.get_at_frame_boundary() && - pSnapshot && - (loop_count > 0) && - ((pTrace_reader->get_cur_frame() == snapshot_loop_end_frame) || (status == vogl_gl_replayer::cStatusAtEOF))) - { - status = replayer.begin_applying_snapshot(pSnapshot, false); - if ((status != vogl_gl_replayer::cStatusOK) && (status != vogl_gl_replayer::cStatusResizeWindow)) - goto error_exit; - - pTrace_reader->seek_to_frame(static_cast(snapshot_loop_start_frame)); - - vogl_debug_printf("Applying snapshot and seeking back to frame %" PRIi64 "\n", snapshot_loop_start_frame); - loop_count--; - } - else - { - bool print_progress = (status == vogl_gl_replayer::cStatusAtEOF) || - ((replayer.get_at_frame_boundary()) && ((replayer.get_frame_index() % 100) == 0)); - if (print_progress) - { - if (pTrace_reader->get_type() == cBINARY_TRACE_FILE_READER) - { - vogl_binary_trace_file_reader &binary_trace_reader = *static_cast(pTrace_reader.get()); - - vogl_printf("Replay now at frame index %u, trace file offet %" PRIu64 ", GL call counter %" PRIu64 ", %3.2f%% percent complete\n", - replayer.get_frame_index(), - binary_trace_reader.get_cur_file_ofs(), - replayer.get_last_parsed_call_counter(), - binary_trace_reader.get_trace_file_size() ? (binary_trace_reader.get_cur_file_ofs() * 100.0f) / binary_trace_reader.get_trace_file_size() : 0); - } - } - - if (status == vogl_gl_replayer::cStatusAtEOF) - { - if (!endless_mode) - { - double time_since_start = tm.get_elapsed_secs(); - - vogl_printf("%u total swaps, %.3f secs, %3.3f avg fps\n", replayer.get_total_swaps(), time_since_start, replayer.get_frame_index() / time_since_start); - break; - } - - vogl_printf("Resetting state and rewinding back to frame 0\n"); - - replayer.reset_state(); - - if (!pTrace_reader->seek_to_frame(0)) - { - vogl_error_printf("Failed rewinding trace reader!\n"); - goto error_exit; - } - } - } - - telemetry_tick(); - } - - normal_exit: - return true; - - error_exit: - return false; - } - - //---------------------------------------------------------------------------------------------------------------------- - // xerror_handler - //---------------------------------------------------------------------------------------------------------------------- - static int xerror_handler(Display *dsp, XErrorEvent *error) - { - char error_string[256]; - XGetErrorText(dsp, error->error_code, error_string, sizeof(error_string)); - - fprintf(stderr, "voglbench: Fatal X Windows Error: %s\n", error_string); - abort(); - } - #else #error "Need to provide tool_replay_mode for this platform." #endif @@ -943,10 +599,6 @@ int main(int argc, char *argv[]) // Initialize vogl_core. vogl_core_init(); - #if VOGL_PLATFORM_HAS_X11 - XSetErrorHandler(xerror_handler); - #endif - if (!voglbench_init(argc, argv)) { voglbench_deinit(); diff --git a/src/voglcommon/vogl_gl_replayer.cpp b/src/voglcommon/vogl_gl_replayer.cpp index 0881b875..e26c23a5 100644 --- a/src/voglcommon/vogl_gl_replayer.cpp +++ b/src/voglcommon/vogl_gl_replayer.cpp @@ -783,52 +783,6 @@ void vogl_gl_replayer::destroy_contexts() } } - #elif (VOGL_PLATFORM_HAS_X11) - - if ((m_contexts.size()) && (m_pWindow->get_display()) && (GL_ENTRYPOINT(glXMakeCurrent)) && (GL_ENTRYPOINT(glXDestroyContext))) - { - GL_ENTRYPOINT(glXMakeCurrent)(m_pWindow->get_display(), (GLXDrawable)NULL, NULL); - - vogl::vector contexts_to_destroy; - for (context_hash_map::const_iterator it = m_contexts.begin(); it != m_contexts.end(); ++it) - contexts_to_destroy.push_back(it->second); - - // Delete "tail" contexts (ones that are not referenced by any other context) in sharegroups first. - while (contexts_to_destroy.size()) - { - for (int i = 0; i < static_cast(contexts_to_destroy.size()); i++) - { - context_state *pContext_state = contexts_to_destroy[i]; - - vogl_trace_ptr_value trace_context = pContext_state->m_context_desc.get_trace_context(); - - bool skip_context = false; - for (int j = 0; j < static_cast(contexts_to_destroy.size()); j++) - { - if (i == j) - continue; - - if (contexts_to_destroy[j]->m_context_desc.get_trace_share_context() == trace_context) - { - skip_context = true; - break; - } - } - - if (skip_context) - continue; - - // This context may have been the sharegroup's root and could have been already deleted. - if (!pContext_state->m_deleted) - { - GL_ENTRYPOINT(glXDestroyContext)(m_pWindow->get_display(), pContext_state->m_replay_context); - } - - contexts_to_destroy.erase(i); - i--; - } - } - } #else #error "Need vogl_gl_replayer::destroy_contexts this platform" #endif @@ -4034,8 +3988,6 @@ vogl_gl_replayer::status_t vogl_gl_replayer::process_gl_entrypoint_packet_intern #if (VOGL_PLATFORM_HAS_SDL) void *pFunc = (void *)SDL_GL_GetProcAddress(reinterpret_cast(procName)); - #elif (VOGL_PLATFORM_HAS_X11) - void *pFunc = (void *)GL_ENTRYPOINT(glXGetProcAddress)(procName); #else #error "Need to implement GetProcAddress for this platform." void *pFunc = NULL; @@ -4358,24 +4310,10 @@ vogl_gl_replayer::status_t vogl_gl_replayer::process_gl_entrypoint_packet_intern process_entrypoint_warning("glXGetCurrentContext() returned different results while replaying (0x%" PRIX64 ") vs tracing (0x%" PRIX64 ")!\n", (uint64_t)replay_context, (uint64_t)trace_context); } - break; - } -#elif VOGL_PLATFORM_HAS_GLX - case VOGL_ENTRYPOINT_glXGetCurrentContext: - { - - GLReplayContextType replay_context = GL_ENTRYPOINT(glXGetCurrentContext)(); - vogl_trace_ptr_value trace_context = trace_packet.get_return_ptr_value(); - - if ((replay_context != 0) != (trace_context != 0)) - { - process_entrypoint_warning("glXGetCurrentContext() returned different results while replaying (0x%" PRIX64 ") vs tracing (0x%" PRIX64 ")!\n", (uint64_t)replay_context, (uint64_t)trace_context); - } - break; } #else -# error "Need to handle *GetCurrentContext for this platform." +#error "Need to handle *GetCurrentContext for this platform." #endif case VOGL_ENTRYPOINT_glXCreateWindow: case VOGL_ENTRYPOINT_glXDestroyWindow: @@ -4465,7 +4403,9 @@ vogl_gl_replayer::status_t vogl_gl_replayer::process_gl_entrypoint_packet_intern // ----- case VOGL_ENTRYPOINT_glXUseXFont: { - #if (VOGL_PLATFORM_HAS_GLX) + #if VOGL_PLATFORM_HAS_SDL + // TODO: Rely on GLX for now. Support SDL if possible. + #elif VOGL_PLATFORM_HAS_GLX const key_value_map &key_value_map = trace_packet.get_key_value_map(); const dynamic_string *pFont_name = key_value_map.get_string_ptr("font_name"); @@ -4505,7 +4445,7 @@ vogl_gl_replayer::status_t vogl_gl_replayer::process_gl_entrypoint_packet_intern } } #else - VOGL_ASSERT(!"impl - VOGL_ENTRYPOINT_glXUseXFont"); + vogl_warning_printf("impl - VOGL_ENTRYPOINT_glXUseXFont\n"); #endif break; @@ -11333,7 +11273,9 @@ vogl_gl_replayer::status_t vogl_gl_replayer::restore_display_lists(vogl_handle_r vogl_verbose_printf("Recreating %u display lists\n", disp_lists.get_display_list_map().size()); - #if VOGL_PLATFORM_HAS_X11 + #if VOGL_PLATFORM_HAS_SDL + // TODO: Implement this with SDL. Remove the X11 path. + #elif VOGL_PLATFORM_HAS_X11 vogl_xfont_cache xfont_cache(m_pWindow->get_display()); #endif @@ -11358,7 +11300,9 @@ vogl_gl_replayer::status_t vogl_gl_replayer::restore_display_lists(vogl_handle_r { if (disp_list.is_xfont()) { - #if (VOGL_PLATFORM_HAS_X11) + #if VOGL_PLATFORM_HAS_SDL + // TODO: Implement this with SDL. Remove the X11 path. + #elif (VOGL_PLATFORM_HAS_X11) XFontStruct *pXFont = xfont_cache.get_or_create(disp_list.get_xfont_name().get_ptr()); if (!pXFont) { diff --git a/src/voglcommon/vogl_replay_window.cpp b/src/voglcommon/vogl_replay_window.cpp index 34f8b0c6..fd16aa32 100644 --- a/src/voglcommon/vogl_replay_window.cpp +++ b/src/voglcommon/vogl_replay_window.cpp @@ -30,11 +30,6 @@ vogl_replay_window::vogl_replay_window() : #if VOGL_PLATFORM_HAS_SDL m_win(NULL) -#elif VOGL_PLATFORM_HAS_X11 - m_win((Window)NULL) - , m_dpy(NULL) - , m_pFB_configs(NULL) - , m_num_fb_configs(0) #endif , m_width(0) , m_height(0) @@ -75,95 +70,6 @@ bool vogl_replay_window::open(int width, int height, int samples) // Don't actually create the context here, that will be done later. // TODO: Support better window creation modes, like with a particular backbuffer format. - #elif (VOGL_PLATFORM_HAS_GLX) - - if (!check_glx_version()) - return false; - - // TODO: These attribs (especially the sizes) should be passed in by the caller! - int fbAttribs[64]; - - int *pAttribs = fbAttribs; - - *pAttribs++ = GLX_RENDER_TYPE; *pAttribs++ = GLX_RGBA_BIT; - *pAttribs++ = GLX_X_RENDERABLE; *pAttribs++ = True; - *pAttribs++ = GLX_DRAWABLE_TYPE; *pAttribs++ = GLX_WINDOW_BIT; - *pAttribs++ = GLX_DOUBLEBUFFER; *pAttribs++ = True; - *pAttribs++ = GLX_RED_SIZE; *pAttribs++ = 8; - *pAttribs++ = GLX_BLUE_SIZE; *pAttribs++ = 8; - *pAttribs++ = GLX_GREEN_SIZE; *pAttribs++ = 8; - *pAttribs++ = GLX_ALPHA_SIZE; *pAttribs++ = 8; - *pAttribs++ = GLX_DEPTH_SIZE; *pAttribs++ = 24; - *pAttribs++ = GLX_STENCIL_SIZE; *pAttribs++ = 8; - - if (samples > 1) - { - *pAttribs++ = GLX_SAMPLE_BUFFERS; *pAttribs++ = 1; - *pAttribs++ = GLX_SAMPLES; *pAttribs++ = samples; - } - - *pAttribs++ = 0; - - // Tell X we are going to use the display - m_dpy = XOpenDisplay(NULL); - if (!m_dpy) - { - vogl_error_printf("XOpenDisplay() failed!\n"); - return false; - } - - // Get a new fb config that meets our attrib requirements - - m_pFB_configs = GL_ENTRYPOINT(glXChooseFBConfig)(m_dpy, DefaultScreen(m_dpy), fbAttribs, &m_num_fb_configs); - if ((!m_pFB_configs) || (!m_num_fb_configs)) - { - vogl_error_printf("glXChooseFBConfig() failed!\n"); - return false; - } - - XVisualInfo *pVisual_info = GL_ENTRYPOINT(glXGetVisualFromFBConfig)(m_dpy, m_pFB_configs[0]); - if (!pVisual_info) - { - vogl_error_printf("glXGetVisualFromFBConfig() failed!\n"); - return false; - } - - // Now create an X window - XSetWindowAttributes winAttribs; - winAttribs.event_mask = ExposureMask | VisibilityChangeMask | - KeyPressMask | PointerMotionMask | - StructureNotifyMask; - - winAttribs.border_pixel = 0; - winAttribs.bit_gravity = StaticGravity; - winAttribs.colormap = XCreateColormap(m_dpy, - RootWindow(m_dpy, pVisual_info->screen), - pVisual_info->visual, AllocNone); - GLint winmask = CWBorderPixel | CWBitGravity | CWEventMask | CWColormap; - - m_win = XCreateWindow(m_dpy, DefaultRootWindow(m_dpy), 20, 20, - width, height, 0, - pVisual_info->depth, InputOutput, - pVisual_info->visual, winmask, &winAttribs); - - - XStoreName(m_dpy, m_win, pWindow_name); - XSetIconName(m_dpy, m_win, pWindow_name); - - XSizeHints sh; - utils::zero_object(sh); - sh.x = 0; // slam position up so when/if we resize the window glReadPixels still works as expected (this may be a bug in the NV driver, I dunno yet) - sh.y = 0; - sh.width = sh.min_width = sh.max_width = sh.base_width = width; - sh.height = sh.min_height = sh.max_height = sh.base_height = height; - sh.flags = PSize | PMinSize | PMaxSize | PBaseSize | PPosition; - XSetWMNormalHints(m_dpy, m_win, &sh); - - XResizeWindow(m_dpy, m_win, width, height); - - XMapWindow(m_dpy, m_win); - - //glXWaitX(); #else #error "Need vogl_replay_window::open for this platform" return false; @@ -187,11 +93,6 @@ void vogl_replay_window::set_title(const char *pTitle) { SDL_SetWindowTitle(m_win, pTitle); } - #elif (VOGL_PLATFORM_HAS_GLX) - if (m_win) - { - XStoreName(m_dpy, m_win, pTitle); - } #else VOGL_ASSERT(!"impl"); #error "Need vogl_replay_window::set_title this platform." @@ -210,24 +111,6 @@ bool vogl_replay_window::resize(int new_width, int new_height) #if (VOGL_PLATFORM_HAS_SDL) SDL_SetWindowSize(m_win, new_width, new_height); - - #elif (VOGL_PLATFORM_HAS_GLX) - - XSizeHints sh; - utils::zero_object(sh); - sh.width = sh.min_width = sh.max_width = sh.base_width = new_width; - sh.height = sh.min_height = sh.max_height = sh.base_height = new_height; - sh.flags = PSize | PMinSize | PMaxSize | PBaseSize; - XSetWMNormalHints(m_dpy, m_win, &sh); - //XMapWindow(dpy, win); - - int status = XResizeWindow(m_dpy, m_win, new_width, new_height); - VOGL_ASSERT(status == True); - VOGL_NOTE_UNUSED(status); - - - //glXWaitX(); - #else #error "Need vogl_replay_window::resize this platform." return false; @@ -247,18 +130,6 @@ void vogl_replay_window::close() SDL_DestroyWindow(m_win); m_win = NULL; } - #elif (VOGL_PLATFORM_HAS_GLX) - if (m_win) - { - XDestroyWindow(m_dpy, m_win); - m_win = (Window)NULL; - } - - if (m_dpy) - { - XCloseDisplay(m_dpy); - m_dpy = NULL; - } #else #error "Need vogl_replay_window::close this platform" #endif @@ -293,11 +164,6 @@ bool vogl_replay_window::get_actual_dimensions(uint32_t &width, uint32_t &height return true; - #elif (VOGL_PLATFORM_HAS_GLX) - Window root; - int x, y; - unsigned int border_width, depth; - return (XGetGeometry(m_dpy, m_win, &root, &x, &y, &width, &height, &border_width, &depth) != False); #else #error "Need vogl_replay_window::get_actual_dimensions this platform" #endif @@ -315,10 +181,6 @@ GLReplayContextType vogl_replay_window::create_context(GLReplayContextType repla vogl_debug_printf("SDL ignores certain parameters, e.g. direct: %d!\n", direct); // TODO: This could call create_context instead. return SDL_GL_CreateContext(get_sdlwindow()); - - #elif (VOGL_PLATFORM_HAS_X11) - XVisualInfo *pVisual_info = GL_ENTRYPOINT(glXGetVisualFromFBConfig)(m_dpy, m_pFB_configs[0]); - return GL_ENTRYPOINT(glXCreateContext)(m_dpy, pVisual_info, replay_share_context, direct); #else #error "Need to implement vogl_replay_window::create_context for this platform" return NULL; @@ -337,9 +199,6 @@ GLReplayContextType vogl_replay_window::create_new_context(GLReplayContextType r vogl_debug_printf("SDL ignores certain parameters, e.g. render_type: %d and direct: %d!\n", render_type, direct); // TODO: This could call create_context instead. return SDL_GL_CreateContext(get_sdlwindow()); - - #elif (VOGL_PLATFORM_HAS_X11) - return GL_ENTRYPOINT(glXCreateNewContext)(m_dpy, m_pFB_configs[0], render_type, replay_share_context, direct); #else #error "Need to implement vogl_replay_window::create_context for this platform" return NULL; @@ -359,8 +218,6 @@ GLReplayContextType vogl_replay_window::create_context_attrib(GLReplayContextTyp } return SDL_GL_CreateContext(get_sdlwindow()); - #elif (VOGL_PLATFORM_HAS_X11) - return GL_ENTRYPOINT(glXCreateContextAttribsARB)(m_dpy, m_pFB_configs[0], replay_share_context, direct, pAttrib_list); #else #error "Need to implement vogl_replay_window::create_context_attrib for this platform" return NULL; @@ -372,9 +229,6 @@ bool vogl_replay_window::make_current(GLReplayContextType context) { #if (VOGL_PLATFORM_HAS_SDL) return SDL_GL_MakeCurrent(m_win, context) >= 0; - #elif (VOGL_PLATFORM_HAS_GLX) - GLXDrawable drawable = context ? get_xwindow() : (GLXDrawable)NULL; - return GL_ENTRYPOINT(glXMakeCurrent)(m_dpy, drawable, context); #else #error "Need vogl_replay_window::make_current this platform" return false; @@ -385,8 +239,6 @@ void vogl_replay_window::destroy_context(GLReplayContextType context) { #if (VOGL_PLATFORM_HAS_SDL) SDL_GL_DeleteContext(context); - #elif (VOGL_PLATFORM_HAS_GLX) - GL_ENTRYPOINT(glXDestroyContext)(m_dpy, context); #else #error "Need vogl_replay_window::destroy_context this platform" return -1; @@ -395,9 +247,7 @@ void vogl_replay_window::destroy_context(GLReplayContextType context) Bool vogl_replay_window::is_direct(GLReplayContextType replay_context) { - #if (VOGL_PLATFORM_HAS_X11 && VOGL_PLATFORM_HAS_GLX) - return GL_ENTRYPOINT(glXIsDirect)(m_dpy, replay_context); - #elif (VOGL_PLATFORM_HAS_SDL) + #if (VOGL_PLATFORM_HAS_SDL) // We don't have a good way to ask here, so just say yes. return true ? 1 : 0; #else @@ -410,8 +260,6 @@ void vogl_replay_window::swap_buffers() { #if (VOGL_PLATFORM_HAS_SDL) SDL_GL_SwapWindow(m_win); - #elif (VOGL_PLATFORM_HAS_GLX) - GL_ENTRYPOINT(glXSwapBuffers)(m_dpy, m_win); #else #error "Need vogl_replay_window::swap_buffers this platform" return -1; @@ -424,15 +272,10 @@ Bool vogl_replay_window::query_version(int *out_major, int *out_minor) VOGL_ASSERT(out_major != NULL); VOGL_ASSERT(out_minor != NULL); - #if (VOGL_PLATFORM_HAS_GLX) - return GL_ENTRYPOINT(glXQueryVersion)(m_dpy, out_major, out_minor); - #else - // Other platforms don't have this concept. - (*out_major) = 0; - (*out_minor) = 0; - return 0; - #endif - + // Platforms other than GLX don't have this concept. + (*out_major) = 0; + (*out_minor) = 0; + return 0; } diff --git a/src/voglcommon/vogl_replay_window.h b/src/voglcommon/vogl_replay_window.h index e1c12bd7..2b67df3d 100644 --- a/src/voglcommon/vogl_replay_window.h +++ b/src/voglcommon/vogl_replay_window.h @@ -29,15 +29,13 @@ #include "vogl_common.h" -#if (VOGL_PLATFORM_HAS_SDL) - #define SDL_MAIN_HANDLED 1 - #include "SDL.h" +#if VOGL_PLATFORM_HAS_SDL +#define SDL_MAIN_HANDLED 1 +#include "SDL.h" #endif #if (VOGL_PLATFORM_HAS_SDL) typedef SDL_GLContext GLReplayContextType; -#elif (VOGL_PLATFORM_HAS_GLX) - typedef GLXContext GLReplayContextType; #else #error "Need to define a suitable type for GLReplayContextType for this platform" #endif @@ -58,8 +56,6 @@ class vogl_replay_window { #if (VOGL_PLATFORM_HAS_SDL) return (m_width > 0) && (m_win != NULL); - #elif (VOGL_PLATFORM_HAS_X11) - return (m_width > 0) && (m_dpy != NULL); #else #error "Need is_opened for this platform." #endif @@ -74,20 +70,13 @@ class vogl_replay_window void close(); - #if VOGL_PLATFORM_HAS_X11 - inline Display *get_display() const - { - return m_dpy; - } - inline Window get_xwindow() const - { - return m_win; - } - #elif VOGL_PLATFORM_HAS_SDL + #if VOGL_PLATFORM_HAS_SDL inline SDL_Window* get_sdlwindow() const { return m_win; } + #else + #error "Need get_window for this platform." #endif inline int get_width() const @@ -102,17 +91,6 @@ class vogl_replay_window void update_dimensions(); - #if VOGL_PLATFORM_HAS_X11 - GLXFBConfig *get_fb_configs() const - { - return m_pFB_configs; - } - uint32_t get_num_fb_configs() const - { - return m_num_fb_configs; - } - #endif - bool get_actual_dimensions(uint32_t &width, uint32_t &height) const; // Create a simple context for this window (using glXCreateContext) @@ -138,14 +116,7 @@ class vogl_replay_window private: #if VOGL_PLATFORM_HAS_SDL - SDL_Window* m_win; - -#elif VOGL_PLATFORM_HAS_X11 - Window m_win; - Display *m_dpy; - GLXFBConfig *m_pFB_configs; - int m_num_fb_configs; #endif int m_width; diff --git a/src/voglcore/vogl_build_options.h b/src/voglcore/vogl_build_options.h index 8b0bb931..b004c308 100644 --- a/src/voglcore/vogl_build_options.h +++ b/src/voglcore/vogl_build_options.h @@ -221,7 +221,7 @@ #define VOGL_PLATFORM_SUPPORTS_BTRACE 1 #define VOGL_PLATFORM_HAS_X11 1 #define VOGL_PLATFORM_HAS_UINT 1 - #define VOGL_PLATFORM_HAS_SDL 0 + #define VOGL_PLATFORM_HAS_SDL 1 #elif defined(PLATFORM_OSX) #define VOGL_HAS_PROC_FILESYSTEM 0 diff --git a/src/vogleditor/CMakeLists.txt b/src/vogleditor/CMakeLists.txt index 4f39a308..d419e0b4 100644 --- a/src/vogleditor/CMakeLists.txt +++ b/src/vogleditor/CMakeLists.txt @@ -5,6 +5,8 @@ include("${SRC_DIR}/build_options.cmake") set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${SRC_DIR}/cmake/Modules/") +require_sdl2() + find_package(Qt5 COMPONENTS Widgets Gui Core REQUIRED) find_package(Threads REQUIRED) find_package(X11 REQUIRED) @@ -18,6 +20,7 @@ include_directories( ${SRC_DIR}/libtelemetry ${CMAKE_CURRENT_BINARY_DIR} ${Qt5Widgets_INCLUDE_DIRS} + ${SDL2_INCLUDE} ) set(SRC_LIST @@ -157,7 +160,7 @@ add_executable(${PROJECT_NAME} ${SRC_LIST} ${HEADER_LIST} ${QT_GEN_RESOURCE_RCC_LIST} ) -add_dependencies(${PROJECT_NAME} voglgen_make_inc) +add_dependencies(${PROJECT_NAME} voglgen_make_inc SDL) target_link_libraries(${PROJECT_NAME} Qt5::Widgets @@ -168,6 +171,7 @@ target_link_libraries(${PROJECT_NAME} voglcommon voglcore ${CMAKE_DL_LIBS} - ) + ${SDL2_LIBRARY} +) build_options_finalize() diff --git a/src/vogleditor/vogleditor_tracereplayer.cpp b/src/vogleditor/vogleditor_tracereplayer.cpp index 7146a854..14a2a9af 100644 --- a/src/vogleditor/vogleditor_tracereplayer.cpp +++ b/src/vogleditor/vogleditor_tracereplayer.cpp @@ -57,47 +57,47 @@ static int X11_Pending(Display *display) return(0); } -bool vogleditor_traceReplayer::process_x_events() +bool vogleditor_traceReplayer::process_events() { - while (X11_Pending(m_window.get_display())) + SDL_Event wnd_event; + while (SDL_PollEvent(&wnd_event)) { - XEvent newEvent; + switch(wnd_event.type) + { + case SDL_WINDOWEVENT_SHOWN: + case SDL_WINDOWEVENT_RESTORED: + { + m_pTraceReplayer->update_window_dimensions(); + break; + } - // Watch for new X events - XNextEvent(m_window.get_display(), &newEvent); + case SDL_WINDOWEVENT_MOVED: + case SDL_WINDOWEVENT_RESIZED: + { + m_pTraceReplayer->update_window_dimensions(); + break; + } - switch (newEvent.type) - { - case MapNotify: - { - m_pTraceReplayer->update_window_dimensions(); - break; - } - case ConfigureNotify: - { - m_pTraceReplayer->update_window_dimensions(); - break; - } - case DestroyNotify: - { - vogl_message_printf("Exiting\n"); - return false; - break; - } - case ClientMessage: - { - if(newEvent.xclient.data.l[0] == (int)m_wmDeleteMessage) - { - vogl_message_printf("Exiting\n"); - return false; - } + case SDL_WINDOWEVENT: + { + switch(wnd_event.window.event) + { + case SDL_WINDOWEVENT_CLOSE: + vogl_message_printf("Exiting\n"); + return false; + break; + default: + break; + }; + break; + } - break; - } - default: break; - } + default: + break; + } } + return true; } @@ -111,7 +111,7 @@ bool vogleditor_traceReplayer::applying_snapshot_and_process_resize(const vogl_g vogleditor_output_message("Waiting for replay window to resize."); // Pump X events in case the window is resizing - if (process_x_events()) + if (process_events()) { status = m_pTraceReplayer->process_pending_window_resize(); } @@ -186,7 +186,7 @@ vogleditor_tracereplayer_result vogleditor_traceReplayer::recursive_replay_apica while (m_pTraceReplayer->get_has_pending_window_resize() || m_pTraceReplayer->get_pending_apply_snapshot()) { // Pump X events in case the window is resizing - if (process_x_events()) + if (process_events()) { status = m_pTraceReplayer->process_pending_window_resize(); if (status != vogl_gl_replayer::cStatusResizeWindow) @@ -247,7 +247,7 @@ vogleditor_tracereplayer_result vogleditor_traceReplayer::recursive_replay_apica break; // Pump X events in case the window is resizing - if (process_x_events() == false) + if (process_events() == false) { // most likely the window wants to close, so let's return return VOGLEDITOR_TRR_USER_EXIT; @@ -280,12 +280,6 @@ vogleditor_tracereplayer_result vogleditor_traceReplayer::replay(vogl_trace_file return VOGLEDITOR_TRR_ERROR; } - XSelectInput(m_window.get_display(), m_window.get_xwindow(), - EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | KeymapStateMask); - - m_wmDeleteMessage = XInternAtom(m_window.get_display(), "WM_DELETE_WINDOW", False); - XSetWMProtocols(m_window.get_display(), m_window.get_xwindow(), &m_wmDeleteMessage, 1); - timer tm; tm.start(); @@ -293,7 +287,7 @@ vogleditor_tracereplayer_result vogleditor_traceReplayer::replay(vogl_trace_file for ( ; ; ) { - if (process_x_events() == false) + if (process_events() == false) { result = VOGLEDITOR_TRR_USER_EXIT; break; diff --git a/src/vogleditor/vogleditor_tracereplayer.h b/src/vogleditor/vogleditor_tracereplayer.h index 89201104..be7e1299 100644 --- a/src/vogleditor/vogleditor_tracereplayer.h +++ b/src/vogleditor/vogleditor_tracereplayer.h @@ -36,7 +36,7 @@ class vogleditor_traceReplayer vogleditor_tracereplayer_result take_state_snapshot_if_needed(vogleditor_gl_state_snapshot** ppNewSnapshot, uint32_t apiCallNumber); vogleditor_tracereplayer_result recursive_replay_apicallTreeItem(vogleditor_apiCallTreeItem* pItem, vogleditor_gl_state_snapshot** ppNewSnapshot, uint64_t apiCallNumber); - bool process_x_events(); + bool process_events(); vogl_gl_replayer* m_pTraceReplayer; vogl_replay_window m_window; Atom m_wmDeleteMessage; diff --git a/src/voglreplay/replay_tool_replay.cpp b/src/voglreplay/replay_tool_replay.cpp index 554bd197..02aa5909 100644 --- a/src/voglreplay/replay_tool_replay.cpp +++ b/src/voglreplay/replay_tool_replay.cpp @@ -130,22 +130,6 @@ static const struct { "disable_frontbuffer_restore", cGLReplayerDisableRestoreFrontBuffer }, }; -#if (!VOGL_PLATFORM_HAS_X11) - -bool tool_replay_mode(vogl::vector *desc) -{ - VOGL_VERIFY(!"impl tool_replay_mode"); - return false; -} - -bool tool_play_mode(vogl::vector *desc) -{ - VOGL_VERIFY(!"impl tool_replay_mode"); - return false; -} - -#else - struct replay_data_t { replay_data_t() : @@ -192,8 +176,8 @@ struct replay_data_t Atom wmDeleteMessage; Bool win_mapped; - vogl::hash_map keys_down; - vogl::hash_map keys_pressed; + vogl::hash_map keys_down; + vogl::hash_map keys_pressed; int64_t paused_mode_frame_index; int64_t take_snapshot_at_frame_index; @@ -221,37 +205,6 @@ struct replay_data_t bool benchmark_mode_allow_state_teardown; }; -//---------------------------------------------------------------------------------------------------------------------- -// X11_Pending - from SDL -//---------------------------------------------------------------------------------------------------------------------- -static int X11_Pending(Display *display) -{ - VOGL_FUNC_TRACER - - /* Flush the display connection and look to see if events are queued */ - XFlush(display); - if (XEventsQueued(display, QueuedAlready)) - return 1; - - /* More drastic measures are required -- see if X is ready to talk */ - { - static struct timeval zero_time; /* static == 0 */ - int x11_fd; - fd_set fdset; - - x11_fd = ConnectionNumber(display); - FD_ZERO(&fdset); - FD_SET(x11_fd, &fdset); - if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) - { - return (XPending(display)); - } - } - - /* Oh well, nothing is ready .. */ - return 0; -} - //---------------------------------------------------------------------------------------------------------------------- // read_state_snapshot_from_trace //---------------------------------------------------------------------------------------------------------------------- @@ -401,90 +354,79 @@ static uint32_t get_replayer_flags_from_command_line_params(bool interactive_mod //---------------------------------------------------------------------------------------------------------------------- static int check_events(replay_data_t &rdata) { - vogl::hash_map &keys_down = rdata.keys_down; - vogl::hash_map &keys_pressed = rdata.keys_pressed; + vogl::hash_map &keys_down = rdata.keys_down; + vogl::hash_map &keys_pressed = rdata.keys_pressed; - while (X11_Pending(rdata.window.get_display())) + SDL_Event wnd_event; + while (SDL_PollEvent(&wnd_event)) { - XEvent newEvent; + switch(wnd_event.type) + { + case SDL_KEYDOWN: + { + keys_down.insert(wnd_event.key.keysym.sym); + keys_pressed.insert(wnd_event.key.keysym.sym); + break; + } - // Watch for new X eventsn - XNextEvent(rdata.window.get_display(), &newEvent); + case SDL_KEYUP: + { + keys_down.erase(wnd_event.key.keysym.sym); - switch (newEvent.type) - { - case KeyPress: - { - KeySym xsym = XLookupKeysym(&newEvent.xkey, 0); + break; + } - //printf("KeyPress 0%04" PRIX64 "%" PRIu64 "\n", (uint64_t)xsym, (uint64_t)xsym); + case SDL_WINDOWEVENT: + { + switch(wnd_event.window.event) + { + case SDL_WINDOWEVENT_FOCUS_GAINED: + case SDL_WINDOWEVENT_FOCUS_LOST: + keys_down.reset(); + break; - keys_down.insert(xsym); - keys_pressed.insert(xsym); - break; - } - case KeyRelease: - { - KeySym xsym = XLookupKeysym(&newEvent.xkey, 0); + case SDL_WINDOWEVENT_CLOSE: + vogl_message_printf("Window told to close, exiting.\n"); + return 1; + break; - //printf("KeyRelease 0x%04" PRIX64 " %" PRIu64 "\n", (uint64_t)xsym, (uint64_t)xsym); - keys_down.erase(xsym); - break; - } - case FocusIn: - case FocusOut: - { - //printf("FocusIn/FocusOut\n"); - keys_down.reset(); - break; - } - case MappingNotify: - { - //XRefreshKeyboardMapping(&newEvent); - break; - } - case UnmapNotify: - { - //printf("UnmapNotify\n"); - rdata.win_mapped = false; - keys_down.reset(); - break; - } - case MapNotify: - { - //printf("MapNotify\n"); + case SDL_WINDOWEVENT_SHOWN: + case SDL_WINDOWEVENT_RESTORED: + { + rdata.win_mapped = true; - rdata.win_mapped = true; + keys_down.reset(); - keys_down.reset(); + if (!rdata.replayer.update_window_dimensions()) + return -1; + break; + } - if (!rdata.replayer.update_window_dimensions()) - return -1; - break; - } - case ConfigureNotify: - { - if (!rdata.replayer.update_window_dimensions()) - return -1; - break; - } - case DestroyNotify: - { - vogl_verbose_printf("Exiting\n"); - return 1; - } - case ClientMessage: - { - if (newEvent.xclient.data.l[0] == (int)rdata.wmDeleteMessage) - { - vogl_verbose_printf("Exiting\n"); - return 1; + case SDL_WINDOWEVENT_HIDDEN: + case SDL_WINDOWEVENT_MINIMIZED: + { + rdata.win_mapped = false; + keys_down.reset(); + break; + } + + case SDL_WINDOWEVENT_MOVED: + case SDL_WINDOWEVENT_RESIZED: + { + if (!rdata.replayer.update_window_dimensions()) + return -1; + break; + } + + default: + break; + }; + break; } - break; - } - default: - break; - } + + default: + break; + }; } return 0; @@ -504,8 +446,8 @@ static int do_interactive_mode(replay_data_t &rdata) tmZone(TELEMETRY_LEVEL0, TMZF_NONE, "Interactive"); vogl_gl_replayer &replayer = rdata.replayer; - vogl::hash_map &keys_down = rdata.keys_down; - vogl::hash_map &keys_pressed = rdata.keys_pressed; + vogl::hash_map &keys_down = rdata.keys_down; + vogl::hash_map &keys_pressed = rdata.keys_pressed; // Interactive mode is more of a test bad to validate a bunch of classes. It's kind of gnarly because the replayer's // object can be in odd intermediate/pending states during window resizes - hopefully this complexity will go away @@ -518,9 +460,9 @@ static int do_interactive_mode(replay_data_t &rdata) rdata.take_snapshot_at_frame_index); } - if (keys_pressed.contains('c')) + if (keys_pressed.contains(SDLK_c)) { - keys_pressed.erase('c'); + keys_pressed.erase(SDLK_c); if (replayer.is_valid()) { dynamic_string filename; @@ -535,9 +477,9 @@ static int do_interactive_mode(replay_data_t &rdata) } } - if (keys_pressed.contains('s')) + if (keys_pressed.contains(SDLK_s)) { - keys_pressed.erase('s'); + keys_pressed.erase(SDLK_s); rdata.slow_mode = !rdata.slow_mode; } @@ -554,15 +496,15 @@ static int do_interactive_mode(replay_data_t &rdata) rdata.take_snapshot_at_frame_index = -1; } // Check for pausing - else if (keys_pressed.contains(XK_space)) + else if (keys_pressed.contains(SDLK_SPACE)) { - keys_pressed.erase(XK_space); + keys_pressed.erase(SDLK_SPACE); if (rdata.paused_mode) { vogl_message_printf("Unpausing\n"); - keys_pressed.erase(XK_space); + keys_pressed.erase(SDLK_SPACE); vogl_delete(rdata.pSnapshot); rdata.pSnapshot = NULL; @@ -649,9 +591,9 @@ static int do_interactive_mode(replay_data_t &rdata) rdata.window.set_title(window_title.get_ptr()); } - // At this point, if we're paused the frame snapshot as been applied, and we're just about going to replay the frame's commands. + // At this point, if we're paused the frame snapshot has been applied, and we're just about going to replay the frame's commands. if (((applied_snapshot) || (replayer.get_at_frame_boundary())) && - (keys_pressed.contains('t') || keys_pressed.contains('j'))) + (keys_pressed.contains(SDLK_t) || keys_pressed.contains(SDLK_j))) { uint64_t frame_to_trim; if (rdata.paused_mode) @@ -700,7 +642,7 @@ static int do_interactive_mode(replay_data_t &rdata) system(view_json_spawn_str.get_ptr()); } - if (keys_pressed.contains('j')) + if (keys_pressed.contains(SDLK_j)) { dynamic_string workdir("."); file_utils::full_path(workdir); @@ -712,8 +654,8 @@ static int do_interactive_mode(replay_data_t &rdata) } } - keys_pressed.erase('t'); - keys_pressed.erase('j'); + keys_pressed.erase(SDLK_t); + keys_pressed.erase(SDLK_j); } // Now replay the next frame's GL commands up to the swap @@ -763,10 +705,10 @@ static int do_interactive_mode(replay_data_t &rdata) else if (replayer.get_at_frame_boundary() && (!replayer.get_pending_apply_snapshot())) { // Rewind to beginning - if (keys_pressed.contains('r')) + if (keys_pressed.contains(SDLK_r)) { - bool ctrl = (keys_down.contains(XK_Control_L) || keys_down.contains(XK_Control_R)); - keys_pressed.erase('r'); + bool ctrl = (keys_down.contains(SDLK_LCTRL) || keys_down.contains(SDLK_RCTRL)); + keys_pressed.erase(SDLK_r); vogl_delete(rdata.pSnapshot); rdata.pSnapshot = NULL; @@ -789,9 +731,9 @@ static int do_interactive_mode(replay_data_t &rdata) } } // Seek to last frame - else if (keys_pressed.contains('e')) + else if (keys_pressed.contains(SDLK_e)) { - keys_pressed.erase('e'); + keys_pressed.erase(SDLK_e); if (rdata.paused_mode) { @@ -841,12 +783,12 @@ static int do_interactive_mode(replay_data_t &rdata) seek_to_target_frame = math::clamp(static_cast(max_frame_index * fraction + .5f), 0, max_frame_index - 1); seek_to_closest_keyframe = true; } - else if (keys_pressed.contains(XK_Left) || keys_pressed.contains(XK_Right)) + else if (keys_pressed.contains(SDLK_LEFT) || keys_pressed.contains(SDLK_RIGHT)) { - int dir = keys_pressed.contains(XK_Left) ? -1 : 1; + int dir = keys_pressed.contains(SDLK_LEFT) ? -1 : 1; - bool shift = (keys_down.contains(XK_Shift_L) || keys_down.contains(XK_Shift_R)); - bool ctrl = (keys_down.contains(XK_Control_L) || keys_down.contains(XK_Control_R)); + bool shift = (keys_down.contains(SDLK_LSHIFT) || keys_down.contains(SDLK_RSHIFT)); + bool ctrl = (keys_down.contains(SDLK_LCTRL) || keys_down.contains(SDLK_RCTRL)); int mag = 1; if ((shift) && (ctrl)) @@ -862,10 +804,10 @@ static int do_interactive_mode(replay_data_t &rdata) seek_to_target_frame = target_frame_index; - keys_pressed.erase(XK_Left); - keys_pressed.erase(XK_Right); + keys_pressed.erase(SDLK_LEFT); + keys_pressed.erase(SDLK_RIGHT); - if ((rdata.keyframes.size()) && (keys_down.contains(XK_Alt_L) || keys_down.contains(XK_Alt_R))) + if ((rdata.keyframes.size()) && (keys_down.contains(SDLK_LALT) || keys_down.contains(SDLK_RALT))) { uint32_t keyframe_array_index = 0; for (keyframe_array_index = 1; keyframe_array_index < rdata.keyframes.size(); keyframe_array_index++) @@ -907,11 +849,11 @@ static int do_interactive_mode(replay_data_t &rdata) } } // Check for unpause - else if (keys_pressed.contains(XK_space)) + else if (keys_pressed.contains(SDLK_SPACE)) { vogl_message_printf("Unpausing\n"); - keys_pressed.erase(XK_space); + keys_pressed.erase(SDLK_SPACE); vogl_delete(rdata.pSnapshot); rdata.pSnapshot = NULL; @@ -1507,14 +1449,6 @@ bool tool_replay_mode(vogl::vector *desc) rdata.replayer.set_dump_framebuffer_on_draw_first_gl_call_index(g_command_line_params().get_value_as_int("dump_framebuffer_on_draw_first_gl_call", 0, -1, 0, INT_MAX)); rdata.replayer.set_dump_framebuffer_on_draw_last_gl_call_index(g_command_line_params().get_value_as_int("dump_framebuffer_on_draw_last_gl_call", 0, -1, 0, INT_MAX)); - XSelectInput(rdata.window.get_display(), rdata.window.get_xwindow(), - EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask | - PointerMotionMask | ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask | - PropertyChangeMask | StructureNotifyMask | KeymapStateMask); - - rdata.wmDeleteMessage = XInternAtom(rdata.window.get_display(), "WM_DELETE_WINDOW", False); - XSetWMProtocols(rdata.window.get_display(), rdata.window.get_xwindow(), &rdata.wmDeleteMessage, 1); - rdata.keyframe_base_filename = g_command_line_params().get_value_as_string("keyframe_base_filename"); rdata.take_snapshot_at_frame_index = g_command_line_params().get_value_as_int64("pause_on_frame", 0, -1); @@ -1788,31 +1722,36 @@ bool tool_replay_mode(vogl::vector *desc) break; bool exit_flag = false; - while (!exit_flag && X11_Pending(rdata.window.get_display())) + SDL_Event wnd_event; + while (!exit_flag && SDL_PollEvent(&wnd_event)) { - XEvent newEvent; - XNextEvent(rdata.window.get_display(), &newEvent); - - switch (newEvent.type) - { - case KeyPress: - case DestroyNotify: + switch(wnd_event.type) { - exit_flag = true; - break; - } - case ClientMessage: - { - if (newEvent.xclient.data.l[0] == (int)rdata.wmDeleteMessage) + case SDL_KEYUP: exit_flag = true; - break; - } - default: - break; + break; + + case SDL_WINDOWEVENT: + { + switch(wnd_event.window.event) + { + case SDL_WINDOWEVENT_CLOSE: + exit_flag = true; + break; + default: + break; + }; + break; + } + + default: + break; } } + if (exit_flag) break; + vogl_sleep(50); } } @@ -1833,5 +1772,3 @@ bool tool_play_mode(vogl::vector *desc) return tool_replay_mode(desc); } - -#endif // VOGL_PLATFORM_HAS_X11 diff --git a/src/voglreplay/vogl_replay_tool.cpp b/src/voglreplay/vogl_replay_tool.cpp index 1225e88c..43cf14b7 100644 --- a/src/voglreplay/vogl_replay_tool.cpp +++ b/src/voglreplay/vogl_replay_tool.cpp @@ -29,6 +29,11 @@ #include "vogl_colorized_console.h" #include "libtelemetry.h" +#if VOGL_PLATFORM_HAS_SDL +#define SDL_MAIN_HANDLED 1 +#include "SDL.h" +#endif + bool tool_dump_mode(vogl::vector *desc); bool tool_parse_mode(vogl::vector *desc); bool tool_info_mode(vogl::vector *desc); @@ -156,6 +161,8 @@ static void vogl_replay_deinit() { VOGL_FUNC_TRACER + SDL_Quit(); + colorized_console::deinit(); } @@ -432,6 +439,9 @@ static const command_t *vogl_replay_init(int argc, char *argv[]) vogl_set_direct_gl_func_epilog(vogl_direct_gl_func_epilog, NULL); } + if(SDL_Init(SDL_INIT_VIDEO) < 0) + return false; + if (!load_gl()) return NULL; @@ -445,23 +455,6 @@ static const command_t *vogl_replay_init(int argc, char *argv[]) return cmd; } - -#if VOGL_PLATFORM_HAS_X11 - -//---------------------------------------------------------------------------------------------------------------------- -// xerror_handler -//---------------------------------------------------------------------------------------------------------------------- -static int xerror_handler(Display *dsp, XErrorEvent *error) -{ - char error_string[256]; - XGetErrorText(dsp, error->error_code, error_string, sizeof(error_string)); - - vogl_error_printf("vogl Fatal X Windows Error: %s\n", error_string); - abort(); -} - -#endif // VOGL_PLATFORM_HAS_X11 - //---------------------------------------------------------------------------------------------------------------------- // main //---------------------------------------------------------------------------------------------------------------------- @@ -479,10 +472,6 @@ int main(int argc, char *argv[]) // Initialize vogl_core. vogl_core_init(); -#if VOGL_PLATFORM_HAS_X11 - XSetErrorHandler(xerror_handler); -#endif - const command_t *cmd = vogl_replay_init(argc, argv); if (!cmd) {