From 03f8528315fa46c95991a34f3325d7b33ae5538c Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Sat, 02 May 2020 21:48:36 +0000
Subject: [PATCH] Update source to SDL2 2.0.12

---
 source/src/video/raspberry/SDL_rpimouse.c |   46 ++++++++++++++++++++++++++--------------------
 1 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/source/src/video/raspberry/SDL_rpimouse.c b/source/src/video/raspberry/SDL_rpimouse.c
index 4ea976b..378c305 100644
--- a/source/src/video/raspberry/SDL_rpimouse.c
+++ b/source/src/video/raspberry/SDL_rpimouse.c
@@ -1,6 +1,6 @@
 /*
   Simple DirectMedia Layer
-  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -50,6 +50,8 @@
 static void RPI_FreeCursor(SDL_Cursor * cursor);
 static void RPI_WarpMouse(SDL_Window * window, int x, int y);
 static int RPI_WarpMouseGlobal(int x, int y);
+
+static SDL_Cursor *global_cursor;
 
 static SDL_Cursor *
 RPI_CreateDefaultCursor(void)
@@ -126,13 +128,11 @@
         return -1;
     }
     
-    if (cursor == NULL) {
-        /* FIXME: We hide the current mouse's cursor, what we actually need is *_HideCursor */
-
-        if (mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
-            curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
-            if (curdata->element > DISPMANX_NO_HANDLE) {
-                update = vc_dispmanx_update_start(10);
+    if (cursor != global_cursor) {
+        if (global_cursor != NULL) {
+            curdata = (RPI_CursorData *) global_cursor->driverdata;
+            if (curdata && curdata->element > DISPMANX_NO_HANDLE) {
+                update = vc_dispmanx_update_start(0);
                 SDL_assert(update);
                 ret = vc_dispmanx_element_remove(update, curdata->element);
                 SDL_assert(ret == DISPMANX_SUCCESS);
@@ -141,6 +141,10 @@
                 curdata->element = DISPMANX_NO_HANDLE;
             }
         }
+        global_cursor = cursor;
+    }
+
+    if (cursor == NULL) {
         return 0;
     }
     
@@ -152,7 +156,7 @@
     if (mouse->focus == NULL) {
         return -1;
     }
-    
+
     display = SDL_GetDisplayForWindow(mouse->focus);
     if (display == NULL) {
         return -1;
@@ -165,9 +169,9 @@
     
     if (curdata->element == DISPMANX_NO_HANDLE) {
         vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16);
-        vc_dispmanx_rect_set(&dst_rect, mouse->x, mouse->y, curdata->w, curdata->h);
+        vc_dispmanx_rect_set(&dst_rect, mouse->x - curdata->hot_x, mouse->y - curdata->hot_y, curdata->w, curdata->h);
         
-        update = vc_dispmanx_update_start(10);
+        update = vc_dispmanx_update_start(0);
         SDL_assert(update);
 
         env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER);
@@ -184,7 +188,7 @@
                                                     DISPMANX_PROTECTION_NONE,
                                                     &alpha,
                                                     DISPMANX_NO_HANDLE, // clamp
-                                                    VC_IMAGE_ROT0);
+                                                    DISPMANX_NO_ROTATE);
         SDL_assert(curdata->element > DISPMANX_NO_HANDLE);
         ret = vc_dispmanx_update_submit_sync(update);
         SDL_assert(ret == DISPMANX_SUCCESS);
@@ -206,7 +210,7 @@
         
         if (curdata != NULL) {
             if (curdata->element != DISPMANX_NO_HANDLE) {
-                update = vc_dispmanx_update_start(10);
+                update = vc_dispmanx_update_start(0);
                 SDL_assert(update);
                 ret = vc_dispmanx_element_remove(update, curdata->element);
                 SDL_assert(ret == DISPMANX_SUCCESS);
@@ -222,6 +226,9 @@
             SDL_free(cursor->driverdata);
         }
         SDL_free(cursor);
+        if (cursor == global_cursor) {
+            global_cursor = NULL;
+        }
     }
 }
 
@@ -255,7 +262,7 @@
         return 0;
     }
 
-    update = vc_dispmanx_update_start(10);
+    update = vc_dispmanx_update_start(0);
     if (!update) {
         return 0;
     }
@@ -264,8 +271,8 @@
     src_rect.y = 0;
     src_rect.width  = curdata->w << 16;
     src_rect.height = curdata->h << 16;
-    dst_rect.x = x;
-    dst_rect.y = y;
+    dst_rect.x = x - curdata->hot_x;
+    dst_rect.y = y - curdata->hot_y;
     dst_rect.width  = curdata->w;
     dst_rect.height = curdata->h;
 
@@ -311,7 +318,7 @@
         return 0;
     }
 
-    update = vc_dispmanx_update_start(10);
+    update = vc_dispmanx_update_start(0);
     if (!update) {
         return 0;
     }
@@ -320,8 +327,8 @@
     src_rect.y = 0;
     src_rect.width  = curdata->w << 16;
     src_rect.height = curdata->h << 16;
-    dst_rect.x = x;
-    dst_rect.y = y;
+    dst_rect.x = x - curdata->hot_x;
+    dst_rect.y = y - curdata->hot_y;
     dst_rect.width  = curdata->w;
     dst_rect.height = curdata->h;
 
@@ -368,7 +375,6 @@
 void
 RPI_QuitMouse(_THIS)
 {
-    
 }
 
 /* This is called when a mouse motion event occurs */

--
Gitblit v1.9.3