Blender V5.3
GHOST_SystemHeadless.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#pragma once
11
12#include "../GHOST_Types.hh"
13#include "GHOST_System.hh"
14#include "GHOST_WindowNULL.hh"
15
16#if defined(WITH_OPENGL_BACKEND) && defined(__linux__)
17# include "GHOST_ContextEGL.hh"
18#endif
19#ifdef WITH_VULKAN_BACKEND
20# include "GHOST_ContextVK.hh"
21#endif
22#include "GHOST_ContextNone.hh"
23
25
27 public:
29 { /* nop */
30 }
31 ~GHOST_SystemHeadless() override = default;
32
33 bool processEvents(bool /*waitForEvent*/) override
34 {
35 return false;
36 }
38 {
39 return false;
40 }
42 {
43 return GHOST_kSuccess;
44 }
45 GHOST_TSuccess getButtons(GHOST_Buttons & /*buttons*/) const override
46 {
47 return GHOST_kSuccess;
48 }
50 {
53 /* No windowing functionality supported.
54 * In most cases this value doesn't matter for the headless backend.
55 *
56 * Nevertheless, don't advertise support.
57 *
58 * NOTE: order the following flags as they they're declared in the source. */
59 ~(
60 /* Wrap. */
62 /* Wrap. */
64 /* Wrap. */
66 /* Wrap. */
68 /* Wrap. */
70 /* Wrap. */
72 /* Wrap. */
74 /* Wrap. */
76 /* Wrap. */
78 /* Wrap. */
80 /* Wrap. */
82 /* Wrap. */
84
85 );
86 }
87 char *getClipboard(bool /*selection*/) const override
88 {
89 return nullptr;
90 }
91 void putClipboard(const char * /*buffer*/, bool /*selection*/) const override
92 { /* nop */
93 }
94 uint64_t getMilliSeconds() const override
95 {
96 return 0;
97 }
98 uint8_t getNumDisplays() const override
99 {
100 return uint8_t(1);
101 }
102 GHOST_TSuccess getCursorPosition(int32_t & /*x*/, int32_t & /*y*/) const override
103 {
104 return GHOST_kFailure;
105 }
107 {
108 return GHOST_kFailure;
109 }
110 void getMainDisplayDimensions(uint32_t & /*width*/, uint32_t & /*height*/) const override
111 { /* nop */
112 }
113 void getAllDisplayDimensions(uint32_t & /*width*/, uint32_t & /*height*/) const override
114 { /* nop */
115 }
117 {
118 const GHOST_ContextParams context_params_offscreen =
120 /* This may not be used depending on the build configuration. */
121 (void)context_params_offscreen;
122
123 switch (gpu_settings.context_type) {
124#ifdef WITH_VULKAN_BACKEND
125 case GHOST_kDrawingContextTypeVulkan: {
126# if defined(WITH_GHOST_SDL)
127 GHOST_Context *context = new GHOST_ContextVK(
128 context_params_offscreen, nullptr, 1, 1, gpu_settings.preferred_device);
129# elif defined(_WIN32)
130 GHOST_Context *context = new GHOST_ContextVK(
131 context_params_offscreen, (HWND)0, 1, 1, gpu_settings.preferred_device);
132# elif defined(__APPLE__)
133 GHOST_Context *context = new GHOST_ContextVK(
134 context_params_offscreen, nullptr, 1, 1, gpu_settings.preferred_device);
135# else
136 GHOST_Context *context = new GHOST_ContextVK(context_params_offscreen,
138 0,
139 0,
140 nullptr,
141 nullptr,
142 nullptr,
143 1,
144 1,
145 gpu_settings.preferred_device);
146# endif
147 if (context->initializeDrawingContext()) {
148 return context;
149 }
150
151 delete context;
152 return nullptr;
153 }
154#endif
155
156#if defined(WITH_OPENGL_BACKEND) && defined(__linux__)
157 case GHOST_kDrawingContextTypeOpenGL: {
158 GHOST_Context *context;
159 for (int minor = 6; minor >= 3; --minor) {
160 context = new GHOST_ContextEGL((GHOST_System *)this,
161 context_params_offscreen,
162 EGLNativeWindowType(0),
163 EGLNativeDisplayType(EGL_DEFAULT_DISPLAY),
164 EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
165 4,
166 minor,
169 EGL_OPENGL_API);
170
171 if (context->initializeDrawingContext()) {
172 return context;
173 }
174 delete context;
175 context = nullptr;
176 }
177
178 return context;
179 }
180#endif
181
182 default:
183 /* Unsupported backend. */
184 return nullptr;
185 }
186
187 return nullptr;
188 }
190 {
191 delete context;
192
193 return GHOST_kSuccess;
194 }
195
197 {
199
200 if (success) {
201 return GHOST_kSuccess;
202 }
203
204 return GHOST_kFailure;
205 }
206
207 GHOST_IWindow *createWindow(const char *title,
208 int32_t left,
209 int32_t top,
210 uint32_t width,
211 uint32_t height,
213 GHOST_GPUSettings gpu_settings,
214 const bool /*exclusive*/,
215 const bool /*is_dialog*/,
216 const GHOST_IWindow *parent_window) override
217 {
219 gpu_settings);
220 return new GHOST_WindowNULL(title,
221 left,
222 top,
223 width,
224 height,
225 state,
226 parent_window,
227 gpu_settings.context_type,
228 context_params);
229 }
230
232 {
233 return nullptr;
234 }
235};
#define GHOST_OPENGL_EGL_CONTEXT_FLAGS
#define GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY
@ GHOST_kVulkanPlatformHeadless
GHOST_TWindowState
GHOST_TCapabilityFlag
@ GHOST_kCapabilityWindowPosition
@ GHOST_kCapabilityClipboardPrimary
@ GHOST_kCapabilityKeyboardHyperKey
@ GHOST_kCapabilityCursorRGBA
@ GHOST_kCapabilityCursorWarp
@ GHOST_kCapabilityInputIME
@ GHOST_kCapabilityCursorGenerator
@ GHOST_kCapabilityWindowPath
@ GHOST_kCapabilityMultiMonitorPlacement
@ GHOST_kCapabilityClipboardImage
@ GHOST_kCapabilityWindowDecorationStyles
@ GHOST_kCapabilityDesktopSample
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS(gpu_settings)
#define GHOST_CAPABILITY_FLAG_ALL
GHOST_TSuccess
@ GHOST_kFailure
@ GHOST_kSuccess
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS_OFFSCREEN(gpu_settings)
GHOST_TConsoleWindowState
unsigned long long int uint64_t
GHOST_ContextEGL(const GHOST_System *const system, const GHOST_ContextParams &context_params, EGLNativeWindowType nativeWindow, EGLNativeDisplayType nativeDisplay, EGLint contextProfileMask, EGLint contextMajorVersion, EGLint contextMinorVersion, EGLint contextFlags, EGLint contextResetNotificationStrategy, EGLenum api)
GHOST_ContextVK(const GHOST_ContextParams &context_params, GHOST_TVulkanPlatformType platform, Window window, Display *display, wl_surface *wayland_surface, wl_display *wayland_display, const GHOST_ContextVK_WindowInfo *wayland_window_info, int contextMajorVersion, int contextMinorVersion, const GHOST_GPUDevice &preferred_device, const GHOST_WindowHDRInfo *hdr_info_=nullptr)
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &) const override
char * getClipboard(bool) const override
GHOST_TSuccess init() override
bool processEvents(bool) override
uint64_t getMilliSeconds() const override
void getMainDisplayDimensions(uint32_t &, uint32_t &) const override
void getAllDisplayDimensions(uint32_t &, uint32_t &) const override
GHOST_TCapabilityFlag getCapabilities() const override
GHOST_IContext * createOffscreenContext(GHOST_GPUSettings gpu_settings) override
GHOST_IWindow * getWindowUnderCursor(int32_t, int32_t) override
uint8_t getNumDisplays() const override
GHOST_TSuccess setCursorPosition(int32_t, int32_t) override
~GHOST_SystemHeadless() override=default
GHOST_TSuccess getButtons(GHOST_Buttons &) const override
bool setConsoleWindowState(GHOST_TConsoleWindowState) override
GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpu_settings, const bool, const bool, const GHOST_IWindow *parent_window) override
GHOST_TSuccess disposeContext(GHOST_IContext *context) override
void putClipboard(const char *, bool) const override
GHOST_TSuccess getCursorPosition(int32_t &, int32_t &) const override
GHOST_TSuccess init() override
GHOST_WindowNULL(const char *, int32_t, int32_t, uint32_t width, uint32_t height, GHOST_TWindowState state, const GHOST_IWindow *, GHOST_TDrawingContextType, const GHOST_ContextParams &context_params)
const int state
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device