GLVis  v4.2
Accurate and flexible finite element visualization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sdl_windows.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-443271.
4 //
5 // This file is part of the GLVis visualization tool and library. For more
6 // information and source code availability see https://glvis.org.
7 //
8 // GLVis is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #include "sdl_windows.hpp"
13 
14 #ifdef SDL_VIDEO_DRIVER_WINDOWS
15 
16 #include <SDL2/SDL_syswm.h>
17 
18 #include <iostream>
19 
20 using namespace std;
21 
22 struct SdlWindowsPlatform::Impl
23 {
24  HANDLE signal_evt;
25 };
26 
28  : m_impl(new Impl)
29 {
30  m_impl->signal_evt = CreateEventA(nullptr, false, false, "");
31  if (m_impl->signal_evt == NULL)
32  {
33  cerr << "Error: CreateEventA() failed with code " << GetLastError() << endl;
34  }
35 }
36 
38 {
39  CloseHandle(m_impl->signal_evt);
40 }
41 
43 {
44  // This call either waits for an event from Windows to be posted to the main
45  // thread's message queue, or for the event object to be set by one of the
46  // worker threads.
47  // A timeout of 500ms is set to allow for interrupts to be pumped into the
48  // SDL event queue.
49  DWORD retval = MsgWaitForMultipleObjectsEx(1,
50  &(m_impl->signal_evt),
51  500,
52  QS_ALLINPUT,
53  MWMO_INPUTAVAILABLE);
54  if (retval == WAIT_FAILED)
55  {
56  cerr << "Error: MsgWaitForMultipleObjectsEx() failed with code "
57  << GetLastError() << endl;
58  }
59  if (ResetEvent(m_impl->signal_evt) == NULL)
60  {
61  cerr << "Error: ResetEvent() failed with code " << GetLastError() << endl;
62  }
63 }
64 
66 {
67  if (SetEvent(m_impl->signal_evt) == NULL)
68  {
69  cerr << "Error: SetEvent() failed with code " << GetLastError() << endl;
70  }
71 }
72 
73 #endif // SDL_VIDEO_DRIVER_WINDOWS