Blender V5.0
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.h"
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
83 );
84 }
85 char *getClipboard(bool /*selection*/) const override
86 {
87 return nullptr;
88 }
89 void putClipboard(const char * /*buffer*/, bool /*selection*/) const override
90 { /* nop */
91 }
92 uint64_t getMilliSeconds() const override
93 {
94 return 0;
95 }
96 uint8_t getNumDisplays() const override
97 {
98 return uint8_t(1);
99 }
100 GHOST_TSuccess getCursorPosition(int32_t & /*x*/, int32_t & /*y*/) const override
101 {
102 return GHOST_kFailure;
103 }
105 {
106 return GHOST_kFailure;
107 }
108 void getMainDisplayDimensions(uint32_t & /*width*/, uint32_t & /*height*/) const override
109 { /* nop */
110 }
111 void getAllDisplayDimensions(uint32_t & /*width*/, uint32_t & /*height*/) const override
112 { /* nop */
113 }
115 {
116 const GHOST_ContextParams context_params_offscreen =
118 /* This may not be used depending on the build configuration. */
119 (void)context_params_offscreen;
120
121 switch (gpu_settings.context_type) {
122#ifdef WITH_VULKAN_BACKEND
123 case GHOST_kDrawingContextTypeVulkan: {
124# ifdef _WIN32
125 GHOST_Context *context = new GHOST_ContextVK(
126 context_params_offscreen, (HWND)0, 1, 2, gpu_settings.preferred_device);
127# elif defined(__APPLE__)
128 GHOST_Context *context = new GHOST_ContextVK(
129 context_params_offscreen, nullptr, 1, 2, gpu_settings.preferred_device);
130# else
131 GHOST_Context *context = new GHOST_ContextVK(context_params_offscreen,
133 0,
134 0,
135 nullptr,
136 nullptr,
137 nullptr,
138 1,
139 2,
140 gpu_settings.preferred_device);
141# endif
142 if (context->initializeDrawingContext()) {
143 return context;
144 }
145
146 delete context;
147 return nullptr;
148 }
149#endif
150
151#if defined(WITH_OPENGL_BACKEND) && defined(__linux__)
152 case GHOST_kDrawingContextTypeOpenGL: {
153 GHOST_Context *context;
154 for (int minor = 6; minor >= 3; --minor) {
155 context = new GHOST_ContextEGL((GHOST_System *)this,
156 context_params_offscreen,
157 EGLNativeWindowType(0),
158 EGLNativeDisplayType(EGL_DEFAULT_DISPLAY),
159 EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
160 4,
161 minor,
164 EGL_OPENGL_API);
165
166 if (context->initializeDrawingContext()) {
167 return context;
168 }
169 delete context;
170 context = nullptr;
171 }
172
173 return context;
174 }
175#endif
176
177 default:
178 /* Unsupported backend. */
179 return nullptr;
180 }
181
182 return nullptr;
183 }
185 {
186 delete context;
187
188 return GHOST_kSuccess;
189 }
190
192 {
194
195 if (success) {
196 return GHOST_kSuccess;
197 }
198
199 return GHOST_kFailure;
200 }
201
202 GHOST_IWindow *createWindow(const char *title,
204 int32_t top,
205 uint32_t width,
206 uint32_t height,
208 GHOST_GPUSettings gpu_settings,
209 const bool /*exclusive*/,
210 const bool /*is_dialog*/,
211 const GHOST_IWindow *parent_window) override
212 {
214 gpu_settings);
215 return new GHOST_WindowNULL(title,
216 left,
217 top,
218 width,
219 height,
220 state,
221 parent_window,
222 gpu_settings.context_type,
223 context_params);
224 }
225
227 {
228 return nullptr;
229 }
230};
#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_kCapabilityMultiMonitorPlacement
@ GHOST_kCapabilityClipboardImage
@ GHOST_kCapabilityWindowDecorationStyles
@ GHOST_kCapabilityDesktopSample
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS(gpu_settings)
#define GHOST_CAPABILITY_FLAG_ALL
GHOST_TSuccess
Definition GHOST_Types.h:57
@ GHOST_kFailure
Definition GHOST_Types.h:57
@ GHOST_kSuccess
Definition GHOST_Types.h:57
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS_OFFSCREEN(gpu_settings)
GHOST_TConsoleWindowState
unsigned long long int uint64_t
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
uint top
static ulong state[N]
static int left
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device