20 #include <freerdp/config.h>
22 #include <freerdp/gdi/gdi.h>
24 #include "sdl_pointer.hpp"
25 #include "sdl_freerdp.hpp"
26 #include "sdl_touch.hpp"
27 #include "sdl_utils.hpp"
29 #include <SDL3/SDL_mouse.h>
40 static BOOL sdl_Pointer_New(rdpContext* context, rdpPointer* pointer)
42 auto ptr =
reinterpret_cast<sdlPointer*
>(pointer);
44 WINPR_ASSERT(context);
48 rdpGdi* gdi = context->gdi;
51 ptr->size = 4ull * pointer->width * pointer->height;
52 ptr->data = winpr_aligned_malloc(ptr->size, 16);
57 auto data =
static_cast<BYTE*
>(ptr->data);
58 if (!freerdp_image_copy_from_pointer_data(
59 data, gdi->dstFormat, 0, 0, 0, pointer->width, pointer->height, pointer->xorMaskData,
60 pointer->lengthXorMask, pointer->andMaskData, pointer->lengthAndMask, pointer->xorBpp,
61 &context->gdi->palette))
63 winpr_aligned_free(ptr->data);
70 static void sdl_Pointer_Clear(sdlPointer* ptr)
73 SDL_DestroyCursor(ptr->cursor);
74 SDL_DestroySurface(ptr->image);
75 ptr->cursor =
nullptr;
79 static void sdl_Pointer_Free(rdpContext* context, rdpPointer* pointer)
81 auto ptr =
reinterpret_cast<sdlPointer*
>(pointer);
82 WINPR_UNUSED(context);
86 sdl_Pointer_Clear(ptr);
87 winpr_aligned_free(ptr->data);
92 static BOOL sdl_Pointer_SetDefault(rdpContext* context)
94 WINPR_UNUSED(context);
96 return sdl_push_user_event(SDL_EVENT_USER_POINTER_DEFAULT);
99 static BOOL sdl_Pointer_Set(rdpContext* context, rdpPointer* pointer)
101 auto sdl = get_context(context);
103 return sdl_push_user_event(SDL_EVENT_USER_POINTER_SET, pointer, sdl);
106 BOOL sdl_Pointer_Set_Process(SDL_UserEvent* uptr)
117 auto sdl =
static_cast<SdlContext*
>(uptr->data2);
120 auto context = sdl->context();
121 auto ptr =
static_cast<sdlPointer*
>(uptr->data1);
124 rdpPointer* pointer = &ptr->pointer;
126 rdpGdi* gdi = context->gdi;
129 x =
static_cast<INT32
>(pointer->xPos);
130 y =
static_cast<INT32
>(pointer->yPos);
131 sw = w =
static_cast<INT32
>(pointer->width);
132 sh = h =
static_cast<INT32
>(pointer->height);
134 SDL_Window* window = SDL_GetMouseFocus();
136 return sdl_Pointer_SetDefault(context);
138 const Uint32
id = SDL_GetWindowID(window);
140 if (!sdl_scale_coordinates(sdl,
id, &x, &y, FALSE, FALSE) ||
141 !sdl_scale_coordinates(sdl,
id, &sw, &sh, FALSE, FALSE))
144 sdl_Pointer_Clear(ptr);
146 ptr->image = SDL_CreateSurface(sw, sh, sdl->sdl_pixel_format);
150 SDL_LockSurface(ptr->image);
151 auto pixels =
static_cast<BYTE*
>(ptr->image->pixels);
152 auto data =
static_cast<const BYTE*
>(ptr->data);
153 const BOOL rc = freerdp_image_scale(
154 pixels, gdi->dstFormat,
static_cast<UINT32
>(ptr->image->pitch), 0, 0,
155 static_cast<UINT32
>(ptr->image->w),
static_cast<UINT32
>(ptr->image->h), data,
156 gdi->dstFormat, 0, 0, 0,
static_cast<UINT32
>(w),
static_cast<UINT32
>(h));
157 SDL_UnlockSurface(ptr->image);
161 ptr->cursor = SDL_CreateColorCursor(ptr->image, x, y);
165 SDL_SetCursor(ptr->cursor);
170 static BOOL sdl_Pointer_SetNull(rdpContext* context)
172 WINPR_UNUSED(context);
174 return sdl_push_user_event(SDL_EVENT_USER_POINTER_NULL);
177 static BOOL sdl_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
179 WINPR_UNUSED(context);
180 WINPR_ASSERT(context);
182 return sdl_push_user_event(SDL_EVENT_USER_POINTER_POSITION, x, y);
185 BOOL sdl_register_pointer(rdpGraphics* graphics)
187 const rdpPointer pointer = {
sizeof(sdlPointer),
192 sdl_Pointer_SetDefault,
193 sdl_Pointer_SetPosition,
205 graphics_register_pointer(graphics, &pointer);