Changeset View
Standalone View
source/ps/GameSetup/HWDetect.cpp
Show All 37 Lines | |||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/scripting/JSInterface_Debug.h" | #include "ps/scripting/JSInterface_Debug.h" | ||||
#include "ps/UserReport.h" | #include "ps/UserReport.h" | ||||
#include "ps/VideoMode.h" | #include "ps/VideoMode.h" | ||||
#include "SDL_syswm.h" | |||||
vladislavbelov: It's not usual include, should be in the system "section". Why it's not included in `libsdl.h`? | |||||
Done Inline ActionsWhat do you mean by system section? linkmauve: What do you mean by system section? | |||||
Done Inline Actionsvladislavbelov: https://trac.wildfiregames.com/wiki/Coding_Conventions#Preprocessorinstructions. | |||||
Done Inline ActionsIt isn’t included as part of libsdl.h because it includes a bunch of platform-specific headers we might not want on all platforms, which may pollute the global environment. linkmauve: It isn’t included as part of libsdl.h because it includes a bunch of platform-specific headers… | |||||
#ifdef SDL_VIDEO_DRIVER_X11 | #ifdef SDL_VIDEO_DRIVER_X11 | ||||
#include <GL/glx.h> | #include <GL/glx.h> | ||||
#include "SDL_syswm.h" | |||||
// Define the GLX_MESA_query_renderer macros if built with | // Define the GLX_MESA_query_renderer macros if built with | ||||
// an old Mesa (<10.0) that doesn't provide them | // an old Mesa (<10.0) that doesn't provide them | ||||
#ifndef GLX_MESA_query_renderer | #ifndef GLX_MESA_query_renderer | ||||
#define GLX_MESA_query_renderer 1 | #define GLX_MESA_query_renderer 1 | ||||
#define GLX_RENDERER_VENDOR_ID_MESA 0x8183 | #define GLX_RENDERER_VENDOR_ID_MESA 0x8183 | ||||
#define GLX_RENDERER_DEVICE_ID_MESA 0x8184 | #define GLX_RENDERER_DEVICE_ID_MESA 0x8184 | ||||
#define GLX_RENDERER_VERSION_MESA 0x8185 | #define GLX_RENDERER_VERSION_MESA 0x8185 | ||||
#define GLX_RENDERER_ACCELERATED_MESA 0x8186 | #define GLX_RENDERER_ACCELERATED_MESA 0x8186 | ||||
#define GLX_RENDERER_VIDEO_MEMORY_MESA 0x8187 | #define GLX_RENDERER_VIDEO_MEMORY_MESA 0x8187 | ||||
#define GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA 0x8188 | #define GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA 0x8188 | ||||
#define GLX_RENDERER_PREFERRED_PROFILE_MESA 0x8189 | #define GLX_RENDERER_PREFERRED_PROFILE_MESA 0x8189 | ||||
#define GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA 0x818A | #define GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA 0x818A | ||||
#define GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA 0x818B | #define GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA 0x818B | ||||
#define GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA 0x818C | #define GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA 0x818C | ||||
#define GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA 0x818D | #define GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA 0x818D | ||||
#define GLX_RENDERER_ID_MESA 0x818E | #define GLX_RENDERER_ID_MESA 0x818E | ||||
#endif /* GLX_MESA_query_renderer */ | #endif /* GLX_MESA_query_renderer */ | ||||
#endif | #endif | ||||
static void ReportSDL(const ScriptInterface& scriptInterface, JS::HandleValue settings); | |||||
static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings); | static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings); | ||||
#if ARCH_X86_X64 | #if ARCH_X86_X64 | ||||
void ConvertCaches(const ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, JS::MutableHandleValue ret) | void ConvertCaches(const ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, JS::MutableHandleValue ret) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | #endif | ||||
scriptInterface.SetProperty(settings, "build_clang", (int)CLANG_VERSION); | scriptInterface.SetProperty(settings, "build_clang", (int)CLANG_VERSION); | ||||
scriptInterface.SetProperty(settings, "gfx_card", gfx::CardName()); | scriptInterface.SetProperty(settings, "gfx_card", gfx::CardName()); | ||||
scriptInterface.SetProperty(settings, "gfx_drv_ver", gfx::DriverInfo()); | scriptInterface.SetProperty(settings, "gfx_drv_ver", gfx::DriverInfo()); | ||||
scriptInterface.SetProperty(settings, "snd_card", snd_card); | scriptInterface.SetProperty(settings, "snd_card", snd_card); | ||||
scriptInterface.SetProperty(settings, "snd_drv_ver", snd_drv_ver); | scriptInterface.SetProperty(settings, "snd_drv_ver", snd_drv_ver); | ||||
ReportSDL(scriptInterface, settings); | |||||
ReportGLLimits(scriptInterface, settings); | ReportGLLimits(scriptInterface, settings); | ||||
scriptInterface.SetProperty(settings, "video_desktop_xres", g_VideoMode.GetDesktopXRes()); | scriptInterface.SetProperty(settings, "video_desktop_xres", g_VideoMode.GetDesktopXRes()); | ||||
scriptInterface.SetProperty(settings, "video_desktop_yres", g_VideoMode.GetDesktopYRes()); | scriptInterface.SetProperty(settings, "video_desktop_yres", g_VideoMode.GetDesktopYRes()); | ||||
scriptInterface.SetProperty(settings, "video_desktop_bpp", g_VideoMode.GetDesktopBPP()); | scriptInterface.SetProperty(settings, "video_desktop_bpp", g_VideoMode.GetDesktopBPP()); | ||||
scriptInterface.SetProperty(settings, "video_desktop_freq", g_VideoMode.GetDesktopFreq()); | scriptInterface.SetProperty(settings, "video_desktop_freq", g_VideoMode.GetDesktopFreq()); | ||||
struct utsname un; | struct utsname un; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | #if ARCH_X86_X64 | ||||
scriptInterface.SetProperty(settings, "x86_dcaches", tmpVal); | scriptInterface.SetProperty(settings, "x86_dcaches", tmpVal); | ||||
ConvertTLBs(scriptInterface, &tmpVal); | ConvertTLBs(scriptInterface, &tmpVal); | ||||
scriptInterface.SetProperty(settings, "x86_tlbs", tmpVal); | scriptInterface.SetProperty(settings, "x86_tlbs", tmpVal); | ||||
#endif | #endif | ||||
scriptInterface.SetProperty(settings, "timer_resolution", timer_Resolution()); | scriptInterface.SetProperty(settings, "timer_resolution", timer_Resolution()); | ||||
// The version should be increased for every meaningful change. | // The version should be increased for every meaningful change. | ||||
const int reportVersion = 12; | const int reportVersion = 12; | ||||
Done Inline ActionsIt needs to update the report version. vladislavbelov: It needs to update the report version. | |||||
// Send the same data to the reporting system | // Send the same data to the reporting system | ||||
g_UserReporter.SubmitReport( | g_UserReporter.SubmitReport( | ||||
"hwdetect", | "hwdetect", | ||||
reportVersion, | reportVersion, | ||||
scriptInterface.StringifyJSON(&settings, false), | scriptInterface.StringifyJSON(&settings, false), | ||||
scriptInterface.StringifyJSON(&settings, true)); | scriptInterface.StringifyJSON(&settings, true)); | ||||
// Run the detection script: | // Run the detection script: | ||||
JS::RootedValue global(cx, scriptInterface.GetGlobalObject()); | JS::RootedValue global(cx, scriptInterface.GetGlobalObject()); | ||||
scriptInterface.CallFunctionVoid(global, "RunHardwareDetection", settings); | scriptInterface.CallFunctionVoid(global, "RunHardwareDetection", settings); | ||||
} | } | ||||
static void ReportSDL(const ScriptInterface& scriptInterface, JS::HandleValue settings) | |||||
Done Inline ActionsI think just SDL, as most of SDL API doesn't contain 2 in names. vladislavbelov: I think just `SDL`, as most of `SDL` API doesn't contain `2` in names. | |||||
{ | |||||
SDL_SysWMinfo wminfo; | |||||
SDL_version linked; | |||||
Done Inline ActionsIt returns compiled version: https://wiki.libsdl.org/SDL_version. vladislavbelov: It returns compiled version: https://wiki.libsdl.org/SDL_version. | |||||
SDL_VERSION(&wminfo.version); | |||||
char version[16]; | |||||
Done Inline ActionsWe use the secure function instead sprintf_s. vladislavbelov: We use the secure function instead `sprintf_s`. | |||||
sprintf_s(version, 16, "%d.%d.%d", wminfo.version.major, wminfo.version.minor, wminfo.version.patch); | |||||
Done Inline ActionsUse ARRAY_SIZE(version) instead of 16. vladislavbelov: Use `ARRAY_SIZE(version)` instead of `16`. | |||||
Not Done Inline Actions"sdl_*" here and below. vladislavbelov: `"sdl_*"` here and below. | |||||
scriptInterface.SetProperty(settings, "sdl2_build_version", version); | |||||
SDL_GetVersion(&linked); | |||||
Done Inline ActionsEarly return instead and use the return value in-place. vladislavbelov: Early return instead and use the return value in-place. | |||||
sprintf_s(version, 16, "%d.%d.%d", linked.major, linked.minor, linked.patch); | |||||
Done Inline ActionsUse ARRAY_SIZE(version) instead of 16. vladislavbelov: Use `ARRAY_SIZE(version)` instead of `16`. | |||||
scriptInterface.SetProperty(settings, "sdl2_runtime_version", version); | |||||
Done Inline ActionsI'd like to use std::string here if possible, as we don't have frequent allocations here. vladislavbelov: I'd like to use `std::string` here if possible, as we don't have frequent allocations here. | |||||
if (!SDL_GetWindowWMInfo(g_VideoMode.GetWindow(), &wminfo)) | |||||
{ | |||||
Done Inline Actionscase should have the same indentation as the switch: https://trac.wildfiregames.com/wiki/Coding_Conventions. vladislavbelov: `case` should have the same indentation as the `switch`: https://trac.wildfiregames. | |||||
scriptInterface.SetProperty(settings, "sdl2_video_backend", "unknown"); | |||||
Done Inline ActionsYou might want to print error in that case (SDL_GetError()). vladislavbelov: You might want to print error in that case (`SDL_GetError()`). | |||||
return; | |||||
Not Done Inline ActionsI mean to print the real error, it's available from SDL_GetError(). vladislavbelov: I mean to print the real error, it's available from `SDL_GetError()`. | |||||
} | |||||
std::string backend = "unknown"; | |||||
switch (wminfo.subsystem) | |||||
{ | |||||
case SDL_SYSWM_WAYLAND: | |||||
backend = "Wayland"; | |||||
break; | |||||
case SDL_SYSWM_X11: | |||||
backend = "X11"; | |||||
break; | |||||
case SDL_SYSWM_WINDOWS: | |||||
backend = "Windows"; | |||||
break; | |||||
case SDL_SYSWM_COCOA: | |||||
backend = "Cocoa"; | |||||
break; | |||||
case SDL_SYSWM_UIKIT: | |||||
backend = "UIKit"; | |||||
break; | |||||
case SDL_SYSWM_DIRECTFB: | |||||
Done Inline ActionsWe need to avoid default in switch to not miss a new value, also not all values are reported. vladislavbelov: We need to avoid `default` in switch to not miss a new value, also not all values are reported. | |||||
Done Inline ActionsThis enum is definitely open-ended, with new backends being added in new SDL2 versions, it would break the build on newer releases to not include that default. linkmauve: This enum is definitely open-ended, with new backends being added in new SDL2 versions, it… | |||||
Done Inline ActionsThat's why we can have #if :) We fix the version where we know all values and add default for upper: #if SDL_VERSION_GREATER(2, 0, 10) default: break; #endif vladislavbelov: That's why we can have `#if` :) We fix the version where we know all values and add `default`… | |||||
Done Inline ActionsWhat about LOGWARNING("")? It would be nice to actually have errors when they occur? :) Stan: What about LOGWARNING("")? It would be nice to actually have errors when they occur? :) | |||||
backend = "DirectFB"; | |||||
break; | |||||
#if SDL_VERSION_ATLEAST(2, 0, 4) | |||||
case SDL_SYSWM_ANDROID: | |||||
backend = "Android"; | |||||
break; | |||||
#endif | |||||
default: | |||||
break; | |||||
} | |||||
scriptInterface.SetProperty(settings, "sdl2_video_backend", backend.c_str()); | |||||
} | |||||
static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings) | static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings) | ||||
{ | { | ||||
const char* errstr = "(error)"; | const char* errstr = "(error)"; | ||||
#define INTEGER(id) do { \ | #define INTEGER(id) do { \ | ||||
GLint i = -1; \ | GLint i = -1; \ | ||||
glGetIntegerv(GL_##id, &i); \ | glGetIntegerv(GL_##id, &i); \ | ||||
if (ogl_SquelchError(GL_INVALID_ENUM)) \ | if (ogl_SquelchError(GL_INVALID_ENUM)) \ | ||||
▲ Show 20 Lines • Show All 402 Lines • Show Last 20 Lines |
It's not usual include, should be in the system "section". Why it's not included in libsdl.h?