sdl-common

This commit is contained in:
akallabeth
2025-03-06 16:21:32 +01:00
parent 5139a3a3e5
commit 3551459e2c
7 changed files with 174 additions and 166 deletions

View File

@@ -233,55 +233,6 @@ BOOL sdl_push_user_event(Uint32 type, ...)
return SDL_PushEvent(&ev) == 1;
}
CriticalSection::CriticalSection()
{
InitializeCriticalSection(&_section);
}
CriticalSection::~CriticalSection()
{
DeleteCriticalSection(&_section);
}
void CriticalSection::lock()
{
EnterCriticalSection(&_section);
}
void CriticalSection::unlock()
{
LeaveCriticalSection(&_section);
}
WinPREvent::WinPREvent(bool initial) : _handle(CreateEventA(nullptr, TRUE, initial, nullptr))
{
}
WinPREvent::~WinPREvent()
{
(void)CloseHandle(_handle);
}
void WinPREvent::set()
{
(void)SetEvent(_handle);
}
void WinPREvent::clear()
{
(void)ResetEvent(_handle);
}
bool WinPREvent::isSet() const
{
return WaitForSingleObject(_handle, 0) == WAIT_OBJECT_0;
}
HANDLE WinPREvent::handle() const
{
return _handle;
}
bool sdl_push_quit()
{
SDL_Event ev = {};

View File

@@ -26,39 +26,7 @@
#include <string>
#include <vector>
class CriticalSection
{
public:
CriticalSection();
CriticalSection(const CriticalSection& other) = delete;
CriticalSection(CriticalSection&& other) = delete;
~CriticalSection();
CriticalSection& operator=(const CriticalSection& other) = delete;
CriticalSection& operator=(const CriticalSection&& other) = delete;
void lock();
void unlock();
private:
CRITICAL_SECTION _section{};
};
class WinPREvent
{
public:
explicit WinPREvent(bool initial = false);
~WinPREvent();
void set();
void clear();
[[nodiscard]] bool isSet() const;
[[nodiscard]] HANDLE handle() const;
private:
HANDLE _handle;
};
#include <sdl_common_utils.hpp>
enum
{

View File

@@ -280,55 +280,6 @@ BOOL sdl_push_user_event(Uint32 type, ...)
return SDL_PushEvent(&ev) == 1;
}
CriticalSection::CriticalSection()
{
InitializeCriticalSection(&_section);
}
CriticalSection::~CriticalSection()
{
DeleteCriticalSection(&_section);
}
void CriticalSection::lock()
{
EnterCriticalSection(&_section);
}
void CriticalSection::unlock()
{
LeaveCriticalSection(&_section);
}
WinPREvent::WinPREvent(bool initial) : _handle(CreateEventA(nullptr, TRUE, initial, nullptr))
{
}
WinPREvent::~WinPREvent()
{
(void)CloseHandle(_handle);
}
void WinPREvent::set()
{
(void)SetEvent(_handle);
}
void WinPREvent::clear()
{
(void)ResetEvent(_handle);
}
bool WinPREvent::isSet() const
{
return WaitForSingleObject(_handle, 0) == WAIT_OBJECT_0;
}
HANDLE WinPREvent::handle() const
{
return _handle;
}
bool sdl_push_quit()
{
SDL_Event ev = {};

View File

@@ -28,42 +28,10 @@
#include <memory>
#include <functional>
#include <sdl_common_utils.hpp>
template <typename T> using deleted_unique_ptr = std::unique_ptr<T, std::function<void(T*)>>;
class CriticalSection
{
public:
CriticalSection();
CriticalSection(const CriticalSection& other) = delete;
CriticalSection(CriticalSection&& other) = delete;
~CriticalSection();
CriticalSection& operator=(const CriticalSection& other) = delete;
CriticalSection& operator=(CriticalSection&& other) = delete;
void lock();
void unlock();
private:
CRITICAL_SECTION _section{};
};
class WinPREvent
{
public:
explicit WinPREvent(bool initial = false);
~WinPREvent();
void set();
void clear();
[[nodiscard]] bool isSet() const;
[[nodiscard]] HANDLE handle() const;
private:
HANDLE _handle;
};
enum
{
SDL_EVENT_USER_UPDATE = SDL_EVENT_USER + 1,

View File

@@ -19,7 +19,9 @@
add_subdirectory(aad)
add_subdirectory(res)
add_library(sdl-common-prefs STATIC sdl_prefs.hpp sdl_prefs.cpp scoped_guard.hpp)
add_library(
sdl-common-prefs STATIC sdl_prefs.hpp sdl_prefs.cpp scoped_guard.hpp sdl_common_utils.hpp sdl_common_utils.cpp
)
target_link_libraries(sdl-common-prefs winpr freerdp)
if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)

View File

@@ -0,0 +1,103 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* SDL common utilitis
*
* Copyright 2025 Armin Novak <armin.novak@thincast.com>
* Copyright 2025 Thincast Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "sdl_common_utils.hpp"
CriticalSection::CriticalSection()
{
InitializeCriticalSection(&_section);
}
CriticalSection::~CriticalSection()
{
DeleteCriticalSection(&_section);
}
void CriticalSection::lock()
{
EnterCriticalSection(&_section);
}
void CriticalSection::unlock()
{
LeaveCriticalSection(&_section);
}
WinPREvent::WinPREvent(bool initial) : _handle(CreateEventA(nullptr, TRUE, initial, nullptr))
{
}
WinPREvent::~WinPREvent()
{
(void)CloseHandle(_handle);
}
void WinPREvent::set()
{
(void)SetEvent(_handle);
}
void WinPREvent::clear()
{
(void)ResetEvent(_handle);
}
bool WinPREvent::isSet() const
{
return WaitForSingleObject(_handle, 0) == WAIT_OBJECT_0;
}
HANDLE WinPREvent::handle() const
{
return _handle;
}
bool operator==(const rdpMonitor& l, const rdpMonitor& r)
{
if (l.x != r.x)
return false;
if (l.y != r.y)
return false;
if (l.width != r.width)
return false;
if (l.height != r.height)
return false;
if (l.is_primary != r.is_primary)
return false;
if (l.orig_screen != r.orig_screen)
return false;
return l.attributes == r.attributes;
}
bool operator==(const MONITOR_ATTRIBUTES& l, const MONITOR_ATTRIBUTES& r)
{
if (l.physicalWidth != r.physicalWidth)
return false;
if (l.physicalHeight != r.physicalHeight)
return false;
if (l.orientation != r.orientation)
return false;
if (l.desktopScaleFactor != r.desktopScaleFactor)
return false;
if (l.deviceScaleFactor != r.deviceScaleFactor)
return false;
return true;
}

View File

@@ -0,0 +1,65 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* SDL common utilitis
*
* Copyright 2025 Armin Novak <armin.novak@thincast.com>
* Copyright 2025 Thincast Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <freerdp/settings_types.h>
bool operator==(const MONITOR_ATTRIBUTES& l, const MONITOR_ATTRIBUTES& r);
bool operator==(const rdpMonitor& l, const rdpMonitor& r);
class WinPREvent
{
public:
explicit WinPREvent(bool initial = false);
WinPREvent(const WinPREvent& other) = delete;
WinPREvent(WinPREvent&& other) = delete;
WinPREvent& operator=(const WinPREvent& other) = delete;
WinPREvent& operator=(WinPREvent&& other) = delete;
~WinPREvent();
void set();
void clear();
[[nodiscard]] bool isSet() const;
[[nodiscard]] HANDLE handle() const;
private:
HANDLE _handle;
};
class CriticalSection
{
public:
CriticalSection();
CriticalSection(const CriticalSection& other) = delete;
CriticalSection(CriticalSection&& other) = delete;
~CriticalSection();
CriticalSection& operator=(const CriticalSection& other) = delete;
CriticalSection& operator=(const CriticalSection&& other) = delete;
void lock();
void unlock();
private:
CRITICAL_SECTION _section{};
};