Blender  V3.3
GHOST_ISystem.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
12 #include "GHOST_ISystem.h"
13 
14 #if defined(WITH_HEADLESS)
15 # include "GHOST_SystemNULL.h"
16 #elif defined(WITH_GHOST_X11) && defined(WITH_GHOST_WAYLAND)
17 # include "GHOST_SystemWayland.h"
18 # include "GHOST_SystemX11.h"
19 # include <stdexcept>
20 #elif defined(WITH_GHOST_X11)
21 # include "GHOST_SystemX11.h"
22 #elif defined(WITH_GHOST_WAYLAND)
23 # include "GHOST_SystemWayland.h"
24 #elif defined(WITH_GHOST_SDL)
25 # include "GHOST_SystemSDL.h"
26 #elif defined(WIN32)
27 # include "GHOST_SystemWin32.h"
28 #elif defined(__APPLE__)
29 # include "GHOST_SystemCocoa.h"
30 #endif
31 
33 
35 
37 {
38  GHOST_TSuccess success;
39  if (!m_system) {
40 
41 #if defined(WITH_HEADLESS)
42  /* Pass. */
43 #elif defined(WITH_GHOST_WAYLAND)
44 # if defined(WITH_GHOST_WAYLAND_DYNLOAD)
45  const bool has_wayland_libraries = ghost_wl_dynload_libraries();
46 # else
47  const bool has_wayland_libraries = true;
48 # endif
49 #endif
50 
51 #if defined(WITH_HEADLESS)
52  m_system = new GHOST_SystemNULL();
53 #elif defined(WITH_GHOST_X11) && defined(WITH_GHOST_WAYLAND)
54  /* Special case, try Wayland, fall back to X11. */
55  try {
56  m_system = has_wayland_libraries ? new GHOST_SystemWayland() : nullptr;
57  }
58  catch (const std::runtime_error &) {
59  /* fallback to X11. */
60  delete m_system;
61  m_system = nullptr;
62  }
63  if (!m_system) {
64  m_system = new GHOST_SystemX11();
65  }
66 #elif defined(WITH_GHOST_X11)
67  m_system = new GHOST_SystemX11();
68 #elif defined(WITH_GHOST_WAYLAND)
69  m_system = has_wayland_libraries ? new GHOST_SystemWayland() : nullptr;
70 #elif defined(WITH_GHOST_SDL)
71  m_system = new GHOST_SystemSDL();
72 #elif defined(WIN32)
74 #elif defined(__APPLE__)
76 #endif
77  success = m_system != nullptr ? GHOST_kSuccess : GHOST_kFailure;
78  }
79  else {
80  success = GHOST_kFailure;
81  }
82  if (success) {
83  success = m_system->init();
84  }
85  return success;
86 }
87 
89 {
91  if (m_system) {
92  delete m_system;
93  m_system = nullptr;
94  }
95  else {
96  success = GHOST_kFailure;
97  }
98  return success;
99 }
100 
102 {
103  return m_system;
104 }
105 
107 {
109 }
110 
112 {
113  GHOST_ISystem::m_backtrace_fn = backtrace_fn;
114 }
GHOST_TSuccess
Definition: GHOST_Types.h:74
@ GHOST_kFailure
Definition: GHOST_Types.h:74
@ GHOST_kSuccess
Definition: GHOST_Types.h:74
void(* GHOST_TBacktraceFn)(void *file_handle)
Definition: GHOST_Types.h:45
static GHOST_ISystem * getSystem()
static GHOST_TBacktraceFn getBacktraceFn()
static void setBacktraceFn(GHOST_TBacktraceFn backtrace_fn)
static GHOST_TSuccess disposeSystem()
static GHOST_TSuccess createSystem()
static GHOST_ISystem * m_system
static GHOST_TBacktraceFn m_backtrace_fn
virtual GHOST_TSuccess init()=0