mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-21 07:25:39 -04:00
Misc: Backports from PCSX2 UI
This commit is contained in:
@ -1922,14 +1922,22 @@ FileSystem::POSIXLock::POSIXLock(int fd)
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_ErrorPrintf("lockf() failed: %d", fd);
|
||||
Log_ErrorPrintf("lockf() failed: %d", errno);
|
||||
m_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
FileSystem::POSIXLock::POSIXLock(std::FILE* fp)
|
||||
{
|
||||
POSIXLock(fileno(fp));
|
||||
m_fd = fileno(fp);
|
||||
if (m_fd >= 0)
|
||||
{
|
||||
if (lockf(m_fd, F_LOCK, 0) != 0)
|
||||
{
|
||||
Log_ErrorPrintf("lockf() failed: %d", errno);
|
||||
m_fd = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileSystem::POSIXLock::~POSIXLock()
|
||||
|
@ -18,6 +18,17 @@ static void* GetProcAddressCallback(const char* name)
|
||||
return ::GetProcAddress(GetModuleHandleA("opengl32.dll"), name);
|
||||
}
|
||||
|
||||
static bool ReloadWGL(HDC dc)
|
||||
{
|
||||
if (!gladLoadWGLLoader([](const char* name) -> void* { return wglGetProcAddress(name); }, dc))
|
||||
{
|
||||
Log_ErrorPrint("Loading GLAD WGL functions failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace GL {
|
||||
ContextWGL::ContextWGL(const WindowInfo& wi) : Context(wi) {}
|
||||
|
||||
@ -51,8 +62,8 @@ bool ContextWGL::Initialize(const Version* versions_to_try, size_t num_versions_
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_ErrorPrint("ContextWGL must always start with a valid surface.");
|
||||
return false;
|
||||
if (!CreatePBuffer())
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everything including core/ES requires a dummy profile to load the WGL extensions.
|
||||
@ -149,8 +160,8 @@ std::unique_ptr<Context> ContextWGL::CreateSharedContext(const WindowInfo& wi)
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_ErrorPrint("PBuffer not implemented");
|
||||
return nullptr;
|
||||
if (!context->CreatePBuffer())
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_version.profile == Profile::NoProfile)
|
||||
@ -305,11 +316,37 @@ bool ContextWGL::CreatePBuffer()
|
||||
|
||||
static constexpr const int pb_attribs[] = {0, 0};
|
||||
|
||||
HGLRC temp_rc = nullptr;
|
||||
ScopedGuard temp_rc_guard([&temp_rc, hdc]() {
|
||||
if (temp_rc)
|
||||
{
|
||||
wglMakeCurrent(hdc, nullptr);
|
||||
wglDeleteContext(temp_rc);
|
||||
}
|
||||
});
|
||||
|
||||
if (!GLAD_WGL_ARB_pbuffer)
|
||||
{
|
||||
// we're probably running completely surfaceless... need a temporary context.
|
||||
temp_rc = wglCreateContext(hdc);
|
||||
if (!temp_rc || !wglMakeCurrent(hdc, temp_rc))
|
||||
{
|
||||
Log_ErrorPrint("Failed to create temporary context to load WGL for pbuffer.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReloadWGL(hdc) || !GLAD_WGL_ARB_pbuffer)
|
||||
{
|
||||
Log_ErrorPrint("Missing WGL_ARB_pbuffer");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AssertMsg(m_pixel_format.has_value(), "Has pixel format for pbuffer");
|
||||
HPBUFFERARB pbuffer = wglCreatePbufferARB(hdc, m_pixel_format.value(), 1, 1, pb_attribs);
|
||||
if (!pbuffer)
|
||||
{
|
||||
Log_ErrorPrint("(ContextWGL::CreatePBuffer) wglCreatePbufferARB() failed");
|
||||
Log_ErrorPrintf("(ContextWGL::CreatePBuffer) wglCreatePbufferARB() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -318,7 +355,7 @@ bool ContextWGL::CreatePBuffer()
|
||||
m_dc = wglGetPbufferDCARB(pbuffer);
|
||||
if (!m_dc)
|
||||
{
|
||||
Log_ErrorPrint("(ContextWGL::CreatePbuffer) wglGetPbufferDCARB() failed");
|
||||
Log_ErrorPrintf("(ContextWGL::CreatePbuffer) wglGetPbufferDCARB() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -326,6 +363,7 @@ bool ContextWGL::CreatePBuffer()
|
||||
m_dummy_dc = hdc;
|
||||
m_pbuffer = pbuffer;
|
||||
|
||||
temp_rc_guard.Run();
|
||||
pbuffer_guard.Cancel();
|
||||
hdc_guard.Cancel();
|
||||
hwnd_guard.Cancel();
|
||||
@ -401,7 +439,7 @@ bool ContextWGL::CreateVersionContext(const Version& version, HGLRC share_contex
|
||||
if ((version.major_version >= 2 && !GLAD_WGL_EXT_create_context_es2_profile) ||
|
||||
(version.major_version < 2 && !GLAD_WGL_EXT_create_context_es_profile))
|
||||
{
|
||||
Log_ErrorPrint("WGL_EXT_create_context_es_profile not supported");
|
||||
Log_ErrorPrintf("WGL_EXT_create_context_es_profile not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -437,11 +475,8 @@ bool ContextWGL::CreateVersionContext(const Version& version, HGLRC share_contex
|
||||
}
|
||||
|
||||
// re-init glad-wgl
|
||||
if (make_current && !gladLoadWGLLoader([](const char* name) -> void* { return wglGetProcAddress(name); }, m_dc))
|
||||
{
|
||||
Log_ErrorPrint("Loading GLAD WGL functions failed");
|
||||
if (make_current && !ReloadWGL(m_dc))
|
||||
return false;
|
||||
}
|
||||
|
||||
wglDeleteContext(m_rc);
|
||||
}
|
||||
@ -449,4 +484,4 @@ bool ContextWGL::CreateVersionContext(const Version& version, HGLRC share_contex
|
||||
m_rc = new_rc;
|
||||
return true;
|
||||
}
|
||||
} // namespace GL
|
||||
} // namespace GL
|
@ -12,16 +12,14 @@ class ScopedGuard final
|
||||
public:
|
||||
ALWAYS_INLINE ScopedGuard(T&& func) : m_func(std::forward<T>(func)) {}
|
||||
ALWAYS_INLINE ScopedGuard(ScopedGuard&& other) : m_func(std::move(other.m_func)) { other.m_func = nullptr; }
|
||||
ALWAYS_INLINE ~ScopedGuard() { Invoke(); }
|
||||
|
||||
ALWAYS_INLINE ~ScopedGuard() { Run(); }
|
||||
|
||||
ScopedGuard(const ScopedGuard&) = delete;
|
||||
void operator=(const ScopedGuard&) = delete;
|
||||
|
||||
/// Prevents the function from being invoked when we go out of scope.
|
||||
ALWAYS_INLINE void Cancel() { m_func.reset(); }
|
||||
|
||||
/// Explicitly fires the function.
|
||||
ALWAYS_INLINE void Invoke()
|
||||
/// Runs the destructor function now instead of when we go out of scope.
|
||||
ALWAYS_INLINE void Run()
|
||||
{
|
||||
if (!m_func.has_value())
|
||||
return;
|
||||
@ -30,6 +28,9 @@ public:
|
||||
m_func.reset();
|
||||
}
|
||||
|
||||
/// Prevents the function from being invoked when we go out of scope.
|
||||
ALWAYS_INLINE void Cancel() { m_func.reset(); }
|
||||
|
||||
private:
|
||||
std::optional<T> m_func;
|
||||
};
|
||||
|
@ -241,6 +241,12 @@ public:
|
||||
return m_pStringData->pBuffer;
|
||||
}
|
||||
|
||||
// returns a string view for this string
|
||||
std::string_view GetStringView() const
|
||||
{
|
||||
return IsEmpty() ? std::string_view() : std::string_view(GetCharArray(), GetLength());
|
||||
}
|
||||
|
||||
// creates a new string from the specified format
|
||||
static String FromFormat(const char* FormatString, ...) printflike(1, 2);
|
||||
|
||||
@ -250,10 +256,7 @@ public:
|
||||
// m_pStringData->pBuffer[i]; }
|
||||
operator const char*() const { return GetCharArray(); }
|
||||
operator char*() { return GetWriteableCharArray(); }
|
||||
operator std::string_view() const
|
||||
{
|
||||
return IsEmpty() ? std::string_view() : std::string_view(GetCharArray(), GetLength());
|
||||
}
|
||||
operator std::string_view() const { return GetStringView(); }
|
||||
|
||||
// Will use the string data provided.
|
||||
String& operator=(const String& copyString)
|
||||
|
@ -549,7 +549,7 @@ bool Vulkan::Context::CreateDevice(VkSurfaceKHR surface, bool enable_validation_
|
||||
Log_ErrorPrintf("Vulkan: Failed to find an acceptable graphics queue.");
|
||||
return false;
|
||||
}
|
||||
if (surface && m_present_queue_family_index == queue_family_count)
|
||||
if (surface != VK_NULL_HANDLE && m_present_queue_family_index == queue_family_count)
|
||||
{
|
||||
Log_ErrorPrintf("Vulkan: Failed to find an acceptable present queue.");
|
||||
return false;
|
||||
@ -583,7 +583,7 @@ bool Vulkan::Context::CreateDevice(VkSurfaceKHR surface, bool enable_validation_
|
||||
}};
|
||||
|
||||
device_info.queueCreateInfoCount = 1;
|
||||
if (m_graphics_queue_family_index != m_present_queue_family_index)
|
||||
if (surface != VK_NULL_HANDLE && m_graphics_queue_family_index != m_present_queue_family_index)
|
||||
{
|
||||
device_info.queueCreateInfoCount = 2;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Context
|
||||
public:
|
||||
enum : u32
|
||||
{
|
||||
NUM_COMMAND_BUFFERS = 2
|
||||
NUM_COMMAND_BUFFERS = 3
|
||||
};
|
||||
|
||||
struct OptionalExtensions
|
||||
|
Reference in New Issue
Block a user