Blender  V2.93
GHOST_ISystem.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
28 #include "GHOST_ISystem.h"
29 
30 #if defined(WITH_HEADLESS)
31 # include "GHOST_SystemNULL.h"
32 #elif defined(WITH_GHOST_X11) && defined(WITH_GHOST_WAYLAND)
33 # include "GHOST_SystemWayland.h"
34 # include "GHOST_SystemX11.h"
35 # include <stdexcept>
36 #elif defined(WITH_GHOST_X11)
37 # include "GHOST_SystemX11.h"
38 #elif defined(WITH_GHOST_WAYLAND)
39 # include "GHOST_SystemWayland.h"
40 #elif defined(WITH_GHOST_SDL)
41 # include "GHOST_SystemSDL.h"
42 #elif defined(WIN32)
43 # include "GHOST_SystemWin32.h"
44 #elif defined(__APPLE__)
45 # include "GHOST_SystemCocoa.h"
46 #endif
47 
49 
51 {
52  GHOST_TSuccess success;
53  if (!m_system) {
54 #if defined(WITH_HEADLESS)
55  m_system = new GHOST_SystemNULL();
56 #elif defined(WITH_GHOST_X11) && defined(WITH_GHOST_WAYLAND)
57  /* Special case, try Wayland, fall back to X11. */
58  try {
60  }
61  catch (const std::runtime_error &) {
62  /* fallback to X11. */
63  }
64  if (!m_system) {
65  m_system = new GHOST_SystemX11();
66  }
67 #elif defined(WITH_GHOST_X11)
68  m_system = new GHOST_SystemX11();
69 #elif defined(WITH_GHOST_WAYLAND)
71 #elif defined(WITH_GHOST_SDL)
72  m_system = new GHOST_SystemSDL();
73 #elif defined(WIN32)
75 #elif defined(__APPLE__)
77 #endif
78  success = m_system != NULL ? GHOST_kSuccess : GHOST_kFailure;
79  }
80  else {
81  success = GHOST_kFailure;
82  }
83  if (success) {
84  success = m_system->init();
85  }
86  return success;
87 }
88 
90 {
92  if (m_system) {
93  delete m_system;
94  m_system = NULL;
95  }
96  else {
97  success = GHOST_kFailure;
98  }
99  return success;
100 }
101 
103 {
104  return m_system;
105 }
GHOST_TSuccess
Definition: GHOST_Types.h:91
@ GHOST_kFailure
Definition: GHOST_Types.h:91
@ GHOST_kSuccess
Definition: GHOST_Types.h:91
static GHOST_ISystem * getSystem()
static GHOST_TSuccess disposeSystem()
static GHOST_TSuccess createSystem()
static GHOST_ISystem * m_system
virtual GHOST_TSuccess init()=0