Blender  V2.93
wm_platform_support.c
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) 2019 Blender Foundation.
17  * All rights reserved.
18  */
19 
23 #include "wm_platform_support.h"
24 #include "wm_window_private.h"
25 
26 #include <string.h>
27 
28 #include "BLI_dynstr.h"
29 #include "BLI_fileops.h"
30 #include "BLI_linklist.h"
31 #include "BLI_path_util.h"
32 #include "BLI_string.h"
33 #include "BLI_sys_types.h"
34 
35 #include "BLT_translation.h"
36 
37 #include "BKE_appdir.h"
38 #include "BKE_global.h"
39 
40 #include "GPU_platform.h"
41 
42 #include "GHOST_C-api.h"
43 
44 #define WM_PLATFORM_SUPPORT_TEXT_SIZE 1024
45 
49 static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
50 {
51  const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
52  bool result = false;
53 
54  if (G.factory_startup) {
55  return result;
56  }
57 
58  if (cfgdir) {
59  char filepath[FILE_MAX];
60  BLI_join_dirfile(filepath, sizeof(filepath), cfgdir, BLENDER_PLATFORM_SUPPORT_FILE);
61  LinkNode *lines = BLI_file_read_as_lines(filepath);
62  for (LinkNode *line_node = lines; line_node; line_node = line_node->next) {
63  char *line = line_node->link;
64  if (STREQ(line, platform_support_key)) {
65  result = true;
66  break;
67  }
68  }
69 
70  if (!result && update) {
71  FILE *fp = BLI_fopen(filepath, "a");
72  if (fp) {
73  fprintf(fp, "%s\n", platform_support_key);
74  fclose(fp);
75  }
76  }
77 
78  BLI_file_free_lines(lines);
79  }
80  return result;
81 }
82 
83 static void wm_platform_support_create_link(char *link)
84 {
85  DynStr *ds = BLI_dynstr_new();
86 
87  BLI_dynstr_append(ds, "https://docs.blender.org/manual/en/dev/troubleshooting/gpu/");
88 #if defined(_WIN32)
89  BLI_dynstr_append(ds, "windows/");
90 #elif defined(__APPLE__)
91  BLI_dynstr_append(ds, "apple/");
92 #else /* UNIX */
93  BLI_dynstr_append(ds, "linux/");
94 #endif
95 
97  BLI_dynstr_append(ds, "intel.html");
98  }
100  BLI_dynstr_append(ds, "nvidia.html");
101  }
103  BLI_dynstr_append(ds, "amd.html");
104  }
105  else {
106  BLI_dynstr_append(ds, "unknown.html");
107  }
108 
110  BLI_dynstr_get_cstring_ex(ds, link);
111  BLI_dynstr_free(ds);
112 }
113 
115 {
116  char title[WM_PLATFORM_SUPPORT_TEXT_SIZE];
117  char message[WM_PLATFORM_SUPPORT_TEXT_SIZE];
119 
120  bool result = true;
121 
123  const char *platform_key = GPU_platform_support_level_key();
124 
125  /* Check if previous check matches the current check. Don't update the approval when running in
126  * `background`. this could have been triggered by installing add-ons via installers. */
127  if (support_level != GPU_SUPPORT_LEVEL_UNSUPPORTED && !G.factory_startup &&
128  wm_platform_support_check_approval(platform_key, !G.background)) {
129  /* If it matches the user has confirmed and wishes to use it. */
130  return result;
131  }
132 
133  /* update the message and link based on the found support level */
134  GHOST_DialogOptions dialog_options = 0;
135 
136  switch (support_level) {
137  default:
139  break;
140 
142  size_t slen = 0;
143  STR_CONCAT(title, slen, "Blender - ");
144  STR_CONCAT(
145  title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Limited Platform Support"));
146  slen = 0;
147  STR_CONCAT(
148  message,
149  slen,
151  "Your graphics card or driver has limited support. It may work, but with "
152  "issues."));
153 
154  /* TODO: Extra space is needed for the split function in GHOST_SystemX11. We should change
155  * the behavior in GHOST_SystemX11. */
156  STR_CONCAT(message, slen, "\n \n");
157  STR_CONCAT(
158  message,
159  slen,
161  "Newer graphics drivers may be available to improve Blender support."));
162  STR_CONCAT(message, slen, "\n \n");
163  STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
164  STR_CONCAT(message, slen, GPU_platform_gpu_name());
165 
166  dialog_options = GHOST_DialogWarning;
167  break;
168  }
169 
171  size_t slen = 0;
172  STR_CONCAT(title, slen, "Blender - ");
173  STR_CONCAT(
174  title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Platform Unsupported"));
175  slen = 0;
176  STR_CONCAT(message,
177  slen,
179  "Your graphics card or driver is not supported."));
180 
181  STR_CONCAT(message, slen, "\n \n");
182  STR_CONCAT(
183  message,
184  slen,
186  "Newer graphics drivers may be available to improve Blender support."));
187 
188  STR_CONCAT(message, slen, "\n \n");
189  STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
190  STR_CONCAT(message, slen, GPU_platform_gpu_name());
191  STR_CONCAT(message, slen, "\n \n");
192 
193  STR_CONCAT(message,
194  slen,
195  CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "The program will now close."));
196  dialog_options = GHOST_DialogError;
197  result = false;
198  break;
199  }
200  }
202 
203  bool show_message = ELEM(
205 
206  /* We are running in the background print the message in the console. */
207  if ((G.background || G.debug & G_DEBUG) && show_message) {
208  printf("%s\n\n%s\n%s\n", title, message, link);
209  }
210  if (G.background) {
211  /* Don't show the message-box when running in background mode.
212  * Printing to console is enough. */
213  result = true;
214  }
215  else if (show_message) {
217  title, message, "Find Latest Drivers", "Continue Anyway", link, dialog_options);
218  }
219 
220  return result;
221 }
@ BLENDER_USER_CONFIG
Definition: BKE_appdir.h:81
const char * BKE_appdir_folder_id(const int folder_id, const char *subfolder)
Definition: appdir.c:674
#define BLENDER_PLATFORM_SUPPORT_FILE
Definition: BKE_appdir.h:104
@ G_DEBUG
Definition: BKE_global.h:133
#define BLI_assert(a)
Definition: BLI_assert.h:58
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
int BLI_dynstr_get_len(DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:286
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
void BLI_dynstr_get_cstring_ex(DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL()
Definition: BLI_dynstr.c:299
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
File and directory operations.
void BLI_file_free_lines(struct LinkNode *lines)
Definition: storage.c:639
struct LinkNode * BLI_file_read_as_lines(const char *file) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: storage.c:590
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:1003
#define FILE_MAX
void BLI_join_dirfile(char *__restrict dst, const size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1737
#define STR_CONCAT(dst, len, suffix)
Definition: BLI_string.h:168
#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:76
@ GHOST_DialogError
Definition: GHOST_Types.h:78
@ GHOST_DialogWarning
Definition: GHOST_Types.h:77
const char * GPU_platform_gpu_name(void)
@ GPU_DRIVER_ANY
Definition: GPU_platform.h:56
const char * GPU_platform_support_level_key(void)
eGPUSupportLevel
Definition: GPU_platform.h:59
@ GPU_SUPPORT_LEVEL_LIMITED
Definition: GPU_platform.h:61
@ GPU_SUPPORT_LEVEL_SUPPORTED
Definition: GPU_platform.h:60
@ GPU_SUPPORT_LEVEL_UNSUPPORTED
Definition: GPU_platform.h:62
@ GPU_OS_ANY
Definition: GPU_platform.h:49
@ GPU_DEVICE_ATI
Definition: GPU_platform.h:34
@ GPU_DEVICE_NVIDIA
Definition: GPU_platform.h:33
@ GPU_DEVICE_INTEL
Definition: GPU_platform.h:35
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
eGPUSupportLevel GPU_platform_support_level(void)
Definition: gpu_platform.cc:97
static void update(bNodeTree *ntree)
struct LinkNode * next
Definition: BLI_linklist.h:39
#define G(x, y, z)
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:2455