Blender  V3.3
wm_platform_support.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. All rights reserved. */
3 
7 #include "wm_platform_support.h"
8 #include "wm_window_private.h"
9 
10 #include <string.h>
11 
12 #include "BLI_dynstr.h"
13 #include "BLI_fileops.h"
14 #include "BLI_linklist.h"
15 #include "BLI_path_util.h"
16 #include "BLI_string.h"
17 #include "BLI_sys_types.h"
18 
19 #include "BLT_translation.h"
20 
21 #include "BKE_appdir.h"
22 #include "BKE_global.h"
23 
24 #include "GPU_platform.h"
25 
26 #include "GHOST_C-api.h"
27 
28 #define WM_PLATFORM_SUPPORT_TEXT_SIZE 1024
29 
33 static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
34 {
35  const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
36  bool result = false;
37 
38  if (G.factory_startup) {
39  return result;
40  }
41 
42  if (cfgdir) {
43  char filepath[FILE_MAX];
44  BLI_join_dirfile(filepath, sizeof(filepath), cfgdir, BLENDER_PLATFORM_SUPPORT_FILE);
45  LinkNode *lines = BLI_file_read_as_lines(filepath);
46  for (LinkNode *line_node = lines; line_node; line_node = line_node->next) {
47  char *line = line_node->link;
48  if (STREQ(line, platform_support_key)) {
49  result = true;
50  break;
51  }
52  }
53 
54  if (!result && update) {
55  FILE *fp = BLI_fopen(filepath, "a");
56  if (fp) {
57  fprintf(fp, "%s\n", platform_support_key);
58  fclose(fp);
59  }
60  }
61 
62  BLI_file_free_lines(lines);
63  }
64  return result;
65 }
66 
67 static void wm_platform_support_create_link(char *link)
68 {
69  DynStr *ds = BLI_dynstr_new();
70 
71  BLI_dynstr_append(ds, "https://docs.blender.org/manual/en/dev/troubleshooting/gpu/");
72 #if defined(_WIN32)
73  BLI_dynstr_append(ds, "windows/");
74 #elif defined(__APPLE__)
75  BLI_dynstr_append(ds, "apple/");
76 #else /* UNIX */
77  BLI_dynstr_append(ds, "linux/");
78 #endif
79 
81  BLI_dynstr_append(ds, "intel.html");
82  }
84  BLI_dynstr_append(ds, "nvidia.html");
85  }
87  BLI_dynstr_append(ds, "amd.html");
88  }
89  else {
90  BLI_dynstr_append(ds, "unknown.html");
91  }
92 
94  BLI_dynstr_get_cstring_ex(ds, link);
95  BLI_dynstr_free(ds);
96 }
97 
99 {
100  char title[WM_PLATFORM_SUPPORT_TEXT_SIZE];
101  char message[WM_PLATFORM_SUPPORT_TEXT_SIZE];
103 
104  bool result = true;
105 
107  const char *platform_key = GPU_platform_support_level_key();
108 
109  /* Check if previous check matches the current check. Don't update the approval when running in
110  * `background`. this could have been triggered by installing add-ons via installers. */
111  if (support_level != GPU_SUPPORT_LEVEL_UNSUPPORTED && !G.factory_startup &&
112  wm_platform_support_check_approval(platform_key, !G.background)) {
113  /* If it matches the user has confirmed and wishes to use it. */
114  return result;
115  }
116 
117  /* update the message and link based on the found support level */
118  GHOST_DialogOptions dialog_options = 0;
119 
120  switch (support_level) {
121  default:
123  break;
124 
126  size_t slen = 0;
127  STR_CONCAT(title, slen, "Blender - ");
128  STR_CONCAT(
129  title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Limited Platform Support"));
130  slen = 0;
131  STR_CONCAT(
132  message,
133  slen,
135  "Your graphics card or driver has limited support. It may work, but with "
136  "issues."));
137 
138  /* TODO: Extra space is needed for the split function in GHOST_SystemX11. We should change
139  * the behavior in GHOST_SystemX11. */
140  STR_CONCAT(message, slen, "\n \n");
141  STR_CONCAT(
142  message,
143  slen,
145  "Newer graphics drivers may be available to improve Blender support."));
146  STR_CONCAT(message, slen, "\n \n");
147  STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
148  STR_CONCAT(message, slen, GPU_platform_gpu_name());
149 
150  dialog_options = GHOST_DialogWarning;
151  break;
152  }
153 
155  size_t slen = 0;
156  STR_CONCAT(title, slen, "Blender - ");
157  STR_CONCAT(
158  title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Platform Unsupported"));
159  slen = 0;
160  STR_CONCAT(message,
161  slen,
163  "Your graphics card or driver is not supported."));
164 
165  STR_CONCAT(message, slen, "\n \n");
166  STR_CONCAT(
167  message,
168  slen,
170  "Newer graphics drivers may be available to improve Blender support."));
171 
172  STR_CONCAT(message, slen, "\n \n");
173  STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
174  STR_CONCAT(message, slen, GPU_platform_gpu_name());
175  STR_CONCAT(message, slen, "\n \n");
176 
177  STR_CONCAT(message,
178  slen,
179  CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "The program will now close."));
180  dialog_options = GHOST_DialogError;
181  result = false;
182  break;
183  }
184  }
186 
187  bool show_message = ELEM(
189 
190  /* We are running in the background print the message in the console. */
191  if ((G.background || G.debug & G_DEBUG) && show_message) {
192  printf("%s\n\n%s\n%s\n", title, message, link);
193  }
194  if (G.background) {
195  /* Don't show the message-box when running in background mode.
196  * Printing to console is enough. */
197  result = true;
198  }
199  else if (show_message) {
201  title, message, "Find Latest Drivers", "Continue Anyway", link, dialog_options);
202  }
203 
204  return result;
205 }
const char * BKE_appdir_folder_id(int folder_id, const char *subfolder)
Definition: appdir.c:672
@ BLENDER_USER_CONFIG
Definition: BKE_appdir.h:157
#define BLENDER_PLATFORM_SUPPORT_FILE
Definition: BKE_appdir.h:180
@ G_DEBUG
Definition: BKE_global.h:174
#define BLI_assert(a)
Definition: BLI_assert.h:46
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:50
int BLI_dynstr_get_len(const DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:235
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:281
void BLI_dynstr_get_cstring_ex(const DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL()
Definition: BLI_dynstr.c:240
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:75
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:906
void BLI_file_free_lines(struct LinkNode *lines)
Definition: storage.c:564
struct LinkNode * BLI_file_read_as_lines(const char *file) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: storage.c:518
#define FILE_MAX
void BLI_join_dirfile(char *__restrict dst, size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1531
#define STR_CONCAT(dst, len, suffix)
Definition: BLI_string.h:488
#define ELEM(...)
#define STREQ(a, b)
#define BLT_I18NCONTEXT_ID_WINDOWMANAGER
#define CTX_IFACE_(context, msgid)
GHOST C-API function and type declarations.
GHOST_DialogOptions
Definition: GHOST_Types.h:67
@ GHOST_DialogError
Definition: GHOST_Types.h:69
@ GHOST_DialogWarning
Definition: GHOST_Types.h:68
const char * GPU_platform_gpu_name(void)
@ GPU_DRIVER_ANY
Definition: GPU_platform.h:47
const char * GPU_platform_support_level_key(void)
eGPUSupportLevel
Definition: GPU_platform.h:50
@ GPU_SUPPORT_LEVEL_LIMITED
Definition: GPU_platform.h:52
@ GPU_SUPPORT_LEVEL_SUPPORTED
Definition: GPU_platform.h:51
@ GPU_SUPPORT_LEVEL_UNSUPPORTED
Definition: GPU_platform.h:53
@ GPU_OS_ANY
Definition: GPU_platform.h:40
@ GPU_DEVICE_ATI
Definition: GPU_platform.h:25
@ GPU_DEVICE_NVIDIA
Definition: GPU_platform.h:24
@ GPU_DEVICE_INTEL
Definition: GPU_platform.h:26
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
eGPUSupportLevel GPU_platform_support_level(void)
#define G(x, y, z)
static void update(bNodeTree *ntree)
struct LinkNode * next
Definition: BLI_linklist.h:23
static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
#define WM_PLATFORM_SUPPORT_TEXT_SIZE
bool WM_platform_support_perform_checks()
static void wm_platform_support_create_link(char *link)
void WM_ghost_show_message_box(const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options)
Definition: wm_window.c:2392