[SDL] Add global helper to setup the library.
Call to SDLHelper::Prepare() is needed before first SDL_InitSubSystem(). - Sets hints (SDL configuration vars). - Configures logging.
This commit is contained in:
17
src/xenia/helper/sdl/premake5.lua
Normal file
17
src/xenia/helper/sdl/premake5.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
project_root = "../../../.."
|
||||
include(project_root.."/tools/build")
|
||||
|
||||
group("src")
|
||||
project("xenia-helper-sdl")
|
||||
uuid("84b00ad3-fba3-4561-96c9-1f9993b14c9c")
|
||||
kind("StaticLib")
|
||||
language("C++")
|
||||
links({
|
||||
"SDL2",
|
||||
})
|
||||
defines({
|
||||
})
|
||||
includedirs({
|
||||
})
|
||||
local_platform_files()
|
||||
sdl2_include()
|
||||
81
src/xenia/helper/sdl/sdl_helper.cc
Normal file
81
src/xenia/helper/sdl/sdl_helper.cc
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2020 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "xenia/helper/sdl/sdl_helper.h"
|
||||
|
||||
#include "xenia/base/assert.h"
|
||||
#include "xenia/base/logging.h"
|
||||
|
||||
namespace xe {
|
||||
namespace helper {
|
||||
namespace sdl {
|
||||
bool SDLHelper::is_prepared_ = false;
|
||||
|
||||
bool SDLHelper::Prepare() {
|
||||
if (is_prepared_) {
|
||||
return true;
|
||||
}
|
||||
is_prepared_ = true;
|
||||
|
||||
is_prepared_ &= SetHints();
|
||||
is_prepared_ &= RedirectLog();
|
||||
|
||||
return is_prepared_;
|
||||
}
|
||||
|
||||
bool SDLHelper::SetHints() {
|
||||
bool suc = true;
|
||||
|
||||
// SDL calls timeBeginPeriod(1) but xenia sets this to a lower value before
|
||||
// using NtSetTimerResolution(). Having that value overwritten causes overall
|
||||
// fps drops. Use override priority as timer resolution should always be
|
||||
// managed by xenia. https://bugzilla.libsdl.org/show_bug.cgi?id=5104
|
||||
suc &= SDL_SetHintWithPriority(SDL_HINT_TIMER_RESOLUTION, "0",
|
||||
SDL_HINT_OVERRIDE) == SDL_TRUE;
|
||||
|
||||
return suc;
|
||||
}
|
||||
|
||||
bool SDLHelper::RedirectLog() {
|
||||
// Redirect SDL_Log* output (internal library stuff) to our log system.
|
||||
SDL_LogSetOutputFunction(
|
||||
[](void* userdata, int category, SDL_LogPriority priority,
|
||||
const char* message) {
|
||||
const char* msg_fmt = "SDL: {}";
|
||||
switch (priority) {
|
||||
case SDL_LOG_PRIORITY_VERBOSE:
|
||||
case SDL_LOG_PRIORITY_DEBUG:
|
||||
XELOGD(msg_fmt, message);
|
||||
break;
|
||||
case SDL_LOG_PRIORITY_INFO:
|
||||
XELOGI(msg_fmt, message);
|
||||
break;
|
||||
case SDL_LOG_PRIORITY_WARN:
|
||||
XELOGW(msg_fmt, message);
|
||||
break;
|
||||
case SDL_LOG_PRIORITY_ERROR:
|
||||
case SDL_LOG_PRIORITY_CRITICAL:
|
||||
XELOGE(msg_fmt, message);
|
||||
break;
|
||||
default:
|
||||
XELOGI(msg_fmt, message);
|
||||
assert_always("SDL: Unknown log priority");
|
||||
break;
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
// SDL itself isn't that talkative. Additionally to this settings there are
|
||||
// hints that can be switched on to output additional internal logging
|
||||
// information.
|
||||
SDL_LogSetAllPriority(SDL_LogPriority::SDL_LOG_PRIORITY_VERBOSE);
|
||||
return true;
|
||||
}
|
||||
} // namespace sdl
|
||||
} // namespace helper
|
||||
} // namespace xe
|
||||
38
src/xenia/helper/sdl/sdl_helper.h
Normal file
38
src/xenia/helper/sdl/sdl_helper.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2020 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_HELPER_SDL_SDL_HELPER_H_
|
||||
#define XENIA_HELPER_SDL_SDL_HELPER_H_
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
namespace xe {
|
||||
namespace helper {
|
||||
namespace sdl {
|
||||
// This helper class exists to independently use SDL from different parts of
|
||||
// xenia.
|
||||
class SDLHelper {
|
||||
public:
|
||||
// To configure the SDL library for use in xenia call this function before
|
||||
// SDL_InitSubSystem() is called.
|
||||
static bool Prepare();
|
||||
static bool IsPrepared() { return is_prepared_; }
|
||||
|
||||
private:
|
||||
static bool SetHints();
|
||||
static bool RedirectLog();
|
||||
|
||||
private:
|
||||
static bool is_prepared_;
|
||||
};
|
||||
} // namespace sdl
|
||||
} // namespace helper
|
||||
} // namespace xe
|
||||
|
||||
#endif // XENIA_HELPER_SDL_SDL_HELPER_H_
|
||||
Reference in New Issue
Block a user