changeset 4293:ab0736381727

RT-27184 FB: cursor image is seen when a touch screen is connected
author Rafi Tayar <rafi.tayar@oracle.com>
date Mon, 15 Jul 2013 17:21:12 +0300
parents f5a3e0dfc93a
children cce932bdf120
files modules/graphics/src/main/java/com/sun/glass/ui/lens/LensApplication.java modules/graphics/src/main/java/com/sun/glass/ui/lens/LensCursor.java modules/graphics/src/main/native-glass/lens/cursor/fbCursor/fbCursor.c modules/graphics/src/main/native-glass/lens/cursor/fbCursor/fbDispman.c
diffstat 4 files changed, 64 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/ui/lens/LensApplication.java	Mon Jul 15 14:17:02 2013 +0200
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/lens/LensApplication.java	Mon Jul 15 17:21:12 2013 +0300
@@ -68,6 +68,8 @@
     private static final int DEVICE_MAX = 4;
     /** A running count of the numbers of devices with each device capability */
     private int[] deviceFlags = new int[DEVICE_MAX + 1];
+    /** True if the application wishes to show the cursor */
+    private boolean cursorVisible = true;
 
     Menu windowMenu;
     Menu editMenu;
@@ -631,6 +633,15 @@
                     }
                 }
             }
+
+            if ((flags & (1 << DEVICE_POINTER)) != 0) {
+                // Turn on/off cursor image
+                if (attach && (deviceFlags[DEVICE_POINTER] == 1) && cursorVisible) {
+                     LensCursor.setVisible_impl(true);
+                } else if (!attach && (deviceFlags[DEVICE_POINTER] == 0)) {
+                    LensCursor.setVisible_impl(false);
+                }
+            }
         }
     }
 
@@ -1415,7 +1426,10 @@
 
     @Override
     protected void staticCursor_setVisible(boolean visible) {
-        LensCursor.setVisible_impl(visible);
+        cursorVisible = visible;
+        if (deviceFlags[DEVICE_POINTER] >= 1) {
+            LensCursor.setVisible_impl(visible);
+        }     
     }
 
     @Override
--- a/modules/graphics/src/main/java/com/sun/glass/ui/lens/LensCursor.java	Mon Jul 15 14:17:02 2013 +0200
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/lens/LensCursor.java	Mon Jul 15 17:21:12 2013 +0300
@@ -32,6 +32,7 @@
 import com.sun.glass.ui.Cursor;
 import com.sun.glass.ui.Pixels;
 import com.sun.glass.ui.Size;
+import com.sun.glass.ui.Application;
 
 final class LensCursor extends Cursor {
 
@@ -97,7 +98,9 @@
 
         int type = getType();
         if (type == CURSOR_DISAPPEAR) {
-            _setVisible(false);
+            // CURSOR_DISAPPEAR is mapped to setVisible(false) and will be registered 
+            // in LensApplication as a user preference to not show the cursor.
+            ((LensApplication)Application.GetApplication()).staticCursor_setVisible(false);
         }
     }
 
--- a/modules/graphics/src/main/native-glass/lens/cursor/fbCursor/fbCursor.c	Mon Jul 15 14:17:02 2013 +0200
+++ b/modules/graphics/src/main/native-glass/lens/cursor/fbCursor/fbCursor.c	Mon Jul 15 17:21:12 2013 +0300
@@ -121,8 +121,6 @@
         GLASS_LOG_SEVERE("Cannot write cursor plane");
         return;
     }
-    cursor.isVisible = 1;
-
 
 }
 
@@ -180,7 +178,6 @@
         }
         close(cursor.fd);
         cursor.fd = -1;
-        cursor.isVisible = 0;
     }
 }
 
@@ -192,11 +189,14 @@
 
     if (isVisible) {
         if (!cursor.isVisible && cursor.currentCursor != 0) {
-            glass_cursor_setNativeCursor(cursor.currentCursor);
-        }
+            FBCursorImage *cursorImage = (FBCursorImage *)jlong_to_ptr(cursor.currentCursor);
+            fbCreateCursor(cursorImage->buffer, cursorImage->width, cursorImage->height, cursorImage->bpp);
+        } 
     } else {
         fbCursorClose();
     }
+
+    cursor.isVisible = isVisible;
 }
 
 void glass_cursor_setNativeCursor(jlong nativeCursorPointer) {
@@ -211,9 +211,12 @@
         return;
     }
 
-    fbCursorClose();
     cursor.currentCursor = nativeCursorPointer;
-    fbCreateCursor(cursorImage->buffer, cursorImage->width, cursorImage->height, cursorImage->bpp);
+
+    if (cursor.isVisible) {
+        fbCursorClose();
+        fbCreateCursor(cursorImage->buffer, cursorImage->width, cursorImage->height, cursorImage->bpp);
+    }
 }
 
 void glass_cursor_releaseNativeCursor(jlong nativeCursorPointer) {
@@ -226,6 +229,11 @@
         FBCursorImage *cursorImage = (FBCursorImage *)jlong_to_ptr(nativeCursorPointer);
         free(cursorImage);
     }
+
+    if (cursor.currentCursor == nativeCursorPointer) {
+        fbCursorClose();
+        cursor.currentCursor = 0;
+    }
 }
 
 
--- a/modules/graphics/src/main/native-glass/lens/cursor/fbCursor/fbDispman.c	Mon Jul 15 14:17:02 2013 +0200
+++ b/modules/graphics/src/main/native-glass/lens/cursor/fbCursor/fbDispman.c	Mon Jul 15 17:21:12 2013 +0300
@@ -77,8 +77,10 @@
     DISPMANX_UPDATE_HANDLE_T update;
     DispmanCursorImage *cursorImage = (DispmanCursorImage *)jlong_to_ptr(nativeCursorHandle);
 
-    if (cursorImage != NULL && cursor.element != 0) {
 
+    if (cursorImage != NULL && cursor.element != 0 &&
+        cursor.currentCursor != nativeCursorHandle) 
+    {
         if (cursorImage->width != cursor.cursorWidth ||
                 cursorImage->height != cursor.cursorHeight) {
 
@@ -90,12 +92,13 @@
             fbDispmanAddDispmanxElement();
         }
 
-        update = vc_dispmanx_update_start(0);
-        vc_dispmanx_element_change_source(update, cursor.element, cursorImage->resource);
-        vc_dispmanx_update_submit_sync(update);
+        cursor.currentCursor = nativeCursorHandle;
 
-        cursor.isVisible = 1;
-        cursor.currentCursor = nativeCursorHandle;
+        if (cursor.isVisible) {
+            update = vc_dispmanx_update_start(0);
+            vc_dispmanx_element_change_source(update, cursor.element, cursorImage->resource);
+            vc_dispmanx_update_submit_sync(update);
+        }
     }
 }
 
@@ -252,10 +255,24 @@
     DispmanCursorImage *cursorImage = (DispmanCursorImage *)jlong_to_ptr(nativeCursorHandle);
 
     if (cursorImage != NULL && cursorImage->resource != 0) {
+
+        if (cursor.currentCursor == nativeCursorHandle &&
+            cursor.isVisible) 
+        {
+            DISPMANX_UPDATE_HANDLE_T update;
+            update = vc_dispmanx_update_start(0);
+            vc_dispmanx_element_change_source(update, cursor.element, 0 /* resource*/);
+            vc_dispmanx_update_submit_sync(update);
+        }
+        
         vc_dispmanx_resource_delete(cursorImage->resource);
     }
 
     free(cursorImage);
+
+    if (cursor.currentCursor == nativeCursorHandle) {
+        cursor.currentCursor = 0;
+    }
 }
 
 
@@ -263,16 +280,20 @@
 
     if (isVisible) {
         if (!cursor.isVisible && cursor.currentCursor != 0) {
-            fbDispmanSetNativeCursor(cursor.currentCursor);
+
+            DispmanCursorImage *cursorImage = (DispmanCursorImage *)jlong_to_ptr(cursor.currentCursor);
+            DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0);
+            vc_dispmanx_element_change_source(update, cursor.element, cursorImage->resource);
+            vc_dispmanx_update_submit_sync(update);
         }
     } else {
         DISPMANX_UPDATE_HANDLE_T update;
         update = vc_dispmanx_update_start(0);
         vc_dispmanx_element_change_source(update, cursor.element, 0 /* resource*/);
         vc_dispmanx_update_submit_sync(update);
+    }
 
-        cursor.isVisible = 0;
-    }
+    cursor.isVisible = isVisible;
 }