mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
Merge pull request #11473 from akallabeth/sdl-refactor
Sdl elminiate sdl and rdp thread dependency
This commit is contained in:
@@ -68,6 +68,7 @@ add_subdirectory(res)
|
||||
|
||||
add_library(sdl3-dialogs STATIC ${SRCS})
|
||||
|
||||
set_property(TARGET sdl3-dialogs PROPERTY FOLDER "Client/SDL")
|
||||
target_link_libraries(sdl3-dialogs PRIVATE ${LIBS})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
set(SRCS sdl3_resource_manager.cpp sdl3_resource_manager.hpp)
|
||||
|
||||
add_library(sdl3_client_res STATIC ${SRCS})
|
||||
set_property(TARGET sdl3_client_res PROPERTY FOLDER "Client/SDL")
|
||||
|
||||
if(NOT WITH_SDL_LINK_SHARED)
|
||||
target_link_libraries(sdl3_client_res ${SDL3_STATIC_LIBRARIES})
|
||||
else()
|
||||
|
||||
@@ -278,7 +278,7 @@ static int error_info_to_error(freerdp* instance, DWORD* pcode, char** msg, size
|
||||
|
||||
winpr_asprintf(msg, len, "Terminate with %s due to ERROR_INFO %s [0x%08" PRIx32 "]: %s",
|
||||
sdl_map_error_to_code_tag(code), name, code, str);
|
||||
WLog_DBG(SDL_TAG, "%s", *msg);
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%s", *msg);
|
||||
if (pcode)
|
||||
*pcode = code;
|
||||
return exit_code;
|
||||
@@ -293,17 +293,6 @@ static BOOL sdl_begin_paint(rdpContext* context)
|
||||
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
HANDLE handles[] = { sdl->update_complete.handle(), freerdp_abort_event(context) };
|
||||
const DWORD status = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
|
||||
switch (status)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
sdl->update_complete.clear();
|
||||
|
||||
gdi = context->gdi;
|
||||
WINPR_ASSERT(gdi);
|
||||
WINPR_ASSERT(gdi->primary);
|
||||
@@ -316,25 +305,6 @@ static BOOL sdl_begin_paint(rdpContext* context)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
class SdlEventUpdateTriggerGuard
|
||||
{
|
||||
private:
|
||||
SdlContext* _sdl;
|
||||
|
||||
public:
|
||||
explicit SdlEventUpdateTriggerGuard(SdlContext* sdl) : _sdl(sdl)
|
||||
{
|
||||
}
|
||||
~SdlEventUpdateTriggerGuard()
|
||||
{
|
||||
_sdl->update_complete.set();
|
||||
}
|
||||
SdlEventUpdateTriggerGuard(const SdlEventUpdateTriggerGuard&) = delete;
|
||||
SdlEventUpdateTriggerGuard(SdlEventUpdateTriggerGuard&&) = delete;
|
||||
SdlEventUpdateTriggerGuard& operator=(const SdlEventUpdateTriggerGuard&) = delete;
|
||||
SdlEventUpdateTriggerGuard& operator=(SdlEventUpdateTriggerGuard&&) = delete;
|
||||
};
|
||||
|
||||
static bool sdl_draw_to_window_rect([[maybe_unused]] SdlContext* sdl, SdlWindow& window,
|
||||
SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect)
|
||||
{
|
||||
@@ -432,16 +402,16 @@ static BOOL sdl_draw_to_window(SdlContext* sdl, std::map<Uint32, SdlWindow>& win
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL sdl_end_paint_process(rdpContext* context)
|
||||
/* This function is called when the library completed composing a new
|
||||
* frame. Read out the changed areas and blit them to your output device.
|
||||
* The image buffer will have the format specified by gdi_init
|
||||
*/
|
||||
static BOOL sdl_end_paint(rdpContext* context)
|
||||
{
|
||||
rdpGdi* gdi = nullptr;
|
||||
auto sdl = get_context(context);
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
WINPR_ASSERT(context);
|
||||
|
||||
SdlEventUpdateTriggerGuard guard(sdl);
|
||||
|
||||
gdi = context->gdi;
|
||||
auto gdi = context->gdi;
|
||||
WINPR_ASSERT(gdi);
|
||||
WINPR_ASSERT(gdi->primary);
|
||||
WINPR_ASSERT(gdi->primary->hdc);
|
||||
@@ -463,22 +433,8 @@ static BOOL sdl_end_paint_process(rdpContext* context)
|
||||
rects.push_back({ rgn.x, rgn.y, rgn.w, rgn.h });
|
||||
}
|
||||
|
||||
return sdl_draw_to_window(sdl, sdl->windows, rects);
|
||||
}
|
||||
|
||||
/* This function is called when the library completed composing a new
|
||||
* frame. Read out the changed areas and blit them to your output device.
|
||||
* The image buffer will have the format specified by gdi_init
|
||||
*/
|
||||
static BOOL sdl_end_paint(rdpContext* context)
|
||||
{
|
||||
auto sdl = get_context(context);
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
std::lock_guard<CriticalSection> lock(sdl->critical);
|
||||
const BOOL rc = sdl_push_user_event(SDL_EVENT_USER_UPDATE, context);
|
||||
|
||||
return rc;
|
||||
sdl->_queue.push(rects);
|
||||
return sdl_push_user_event(SDL_EVENT_USER_UPDATE);
|
||||
}
|
||||
|
||||
static void sdl_destroy_primary(SdlContext* sdl)
|
||||
@@ -965,8 +921,12 @@ static int sdl_run(SdlContext* sdl)
|
||||
break;
|
||||
case SDL_EVENT_USER_UPDATE:
|
||||
{
|
||||
auto context = static_cast<rdpContext*>(windowEvent.user.data1);
|
||||
sdl_end_paint_process(context);
|
||||
while (!sdl->_queue.empty())
|
||||
{
|
||||
auto rectangles = sdl->_queue.front();
|
||||
sdl_draw_to_window(sdl, sdl->windows, rectangles);
|
||||
sdl->_queue.pop();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_USER_CREATE_WINDOWS:
|
||||
@@ -1748,7 +1708,6 @@ int main(int argc, char* argv[])
|
||||
|
||||
bool SdlContext::update_fullscreen(bool enter)
|
||||
{
|
||||
std::lock_guard<CriticalSection> lock(critical);
|
||||
for (const auto& window : windows)
|
||||
{
|
||||
if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter))
|
||||
@@ -1760,14 +1719,11 @@ bool SdlContext::update_fullscreen(bool enter)
|
||||
|
||||
bool SdlContext::update_minimize()
|
||||
{
|
||||
std::lock_guard<CriticalSection> lock(critical);
|
||||
return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
|
||||
}
|
||||
|
||||
bool SdlContext::update_resizeable(bool enable)
|
||||
{
|
||||
std::lock_guard<CriticalSection> lock(critical);
|
||||
|
||||
const auto settings = context()->settings;
|
||||
const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
|
||||
const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
|
||||
@@ -1784,8 +1740,8 @@ bool SdlContext::update_resizeable(bool enable)
|
||||
}
|
||||
|
||||
SdlContext::SdlContext(rdpContext* context)
|
||||
: _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
|
||||
clip(this), primary(nullptr, SDL_DestroySurface), rdp_thread_running(false)
|
||||
: _context(context), log(WLog_Get(SDL_TAG)), disp(this), input(this), clip(this),
|
||||
primary(nullptr, SDL_DestroySurface), rdp_thread_running(false)
|
||||
{
|
||||
WINPR_ASSERT(context);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <atomic>
|
||||
#include <queue>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/client/rdpei.h>
|
||||
@@ -85,7 +86,6 @@ class SdlContext
|
||||
std::thread thread;
|
||||
WinPREvent initialize;
|
||||
WinPREvent initialized;
|
||||
WinPREvent update_complete;
|
||||
WinPREvent windows_created;
|
||||
int exit_code = -1;
|
||||
|
||||
@@ -100,4 +100,6 @@ class SdlContext
|
||||
std::unique_ptr<SDLConnectionDialog> connection_dialog;
|
||||
|
||||
std::atomic<bool> rdp_thread_running;
|
||||
|
||||
std::queue<std::vector<SDL_Rect>> _queue;
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ 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)
|
||||
set_property(TARGET sdl-common-prefs PROPERTY FOLDER "Client/Common")
|
||||
|
||||
if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
|
||||
@@ -54,6 +54,8 @@ cleaning_configure_file(sdl_config.hpp.in sdl_config.hpp @ONLY)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_library(sdl-common-aad-view STATIC ${SRCS})
|
||||
set_property(TARGET sdl-common-aad-view PROPERTY FOLDER "Client/Common")
|
||||
|
||||
target_include_directories(sdl-common-aad-view PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(sdl-common-aad-view PRIVATE ${LIBS})
|
||||
target_compile_definitions(sdl-common-aad-view PUBLIC ${DEFINITIONS})
|
||||
|
||||
@@ -105,3 +105,4 @@ endif()
|
||||
|
||||
add_library(sdl-common-client-res STATIC ${RES_FILES} ${SRCS} ${FACTORY_HDR} ${FACTORY_SRCS})
|
||||
set_property(TARGET sdl-common-client-res PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
set_property(TARGET sdl-common-client-res PROPERTY FOLDER "Client/Common")
|
||||
|
||||
@@ -19,6 +19,7 @@ set(SRCS xfreerdp.c)
|
||||
|
||||
addtargetwithresourcefile(${MODULE_NAME} TRUE "${PROJECT_VERSION}" SRCS)
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "..")
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Client/X11")
|
||||
|
||||
list(APPEND LIBS xfreerdp-client)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user