changeset 9950:0abf40ecd9c5

8233255: Better Swing Buttons Reviewed-by: mbalao, andrew Contributed-by: benty@amazon.com
author phh
date Mon, 13 Jul 2020 01:29:26 +0100
parents 09edbf07c17c
children 0d3a0e3144c6
files src/solaris/native/sun/awt/gtk2_interface.c src/solaris/native/sun/awt/swing_GTKEngine.c
diffstat 2 files changed, 43 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/sun/awt/gtk2_interface.c	Sun Jul 12 23:11:42 2020 +0100
+++ b/src/solaris/native/sun/awt/gtk2_interface.c	Mon Jul 13 01:29:26 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -964,45 +964,46 @@
     black = (*fp_gdk_pixbuf_get_pixels)(gtk2_black_pixbuf);
     stride = (*fp_gdk_pixbuf_get_rowstride)(gtk2_black_pixbuf);
     padding = stride - width * 4;
-
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
-            int r1 = *white++;
-            int r2 = *black++;
-            int alpha = 0xff + r2 - r1;
+    if (padding >= 0 && stride > 0) {
+        for (i = 0; i < height; i++) {
+            for (j = 0; j < width; j++) {
+                int r1 = *white++;
+                int r2 = *black++;
+                int alpha = 0xff + r2 - r1;
 
-            switch (alpha) {
-                case 0:       /* transparent pixel */
-                    r = g = b = 0;
-                    black += 3;
-                    white += 3;
-                    is_opaque = FALSE;
-                    break;
+                switch (alpha) {
+                    case 0:       /* transparent pixel */
+                        r = g = b = 0;
+                        black += 3;
+                        white += 3;
+                        is_opaque = FALSE;
+                        break;
 
-                case 0xff:    /* opaque pixel */
-                    r = r2;
-                    g = *black++;
-                    b = *black++;
-                    black++;
-                    white += 3;
-                    break;
+                    case 0xff:    /* opaque pixel */
+                        r = r2;
+                        g = *black++;
+                        b = *black++;
+                        black++;
+                        white += 3;
+                        break;
 
-                default:      /* translucent pixel */
-                    r = 0xff * r2 / alpha;
-                    g = 0xff * *black++ / alpha;
-                    b = 0xff * *black++ / alpha;
-                    black++;
-                    white += 3;
-                    is_opaque = FALSE;
-                    is_bitmask = FALSE;
-                    break;
+                    default:      /* translucent pixel */
+                        r = 0xff * r2 / alpha;
+                        g = 0xff * *black++ / alpha;
+                        b = 0xff * *black++ / alpha;
+                        black++;
+                        white += 3;
+                        is_opaque = FALSE;
+                        is_bitmask = FALSE;
+                        break;
+                }
+
+                *dst++ = (alpha << 24 | r << 16 | g << 8 | b);
             }
 
-            *dst++ = (alpha << 24 | r << 16 | g << 8 | b);
+            white += padding;
+            black += padding;
         }
-
-        white += padding;
-        black += padding;
     }
     return is_opaque ? java_awt_Transparency_OPAQUE :
                        (is_bitmask ? java_awt_Transparency_BITMASK :
--- a/src/solaris/native/sun/awt/swing_GTKEngine.c	Sun Jul 12 23:11:42 2020 +0100
+++ b/src/solaris/native/sun/awt/swing_GTKEngine.c	Mon Jul 13 01:29:26 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,10 @@
  * questions.
  */
 
-#include <stdlib.h>
 #include "gtk2_interface.h"
 #include "com_sun_java_swing_plaf_gtk_GTKEngine.h"
+#include <jni_util.h>
+#include <stdlib.h>
 
 /*
  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
@@ -292,6 +293,11 @@
 Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeStartPainting(
         JNIEnv *env, jobject this, jint w, jint h)
 {
+    if (w > 0x7FFF || h > 0x7FFF || (uintptr_t)4 * w * h > 0x7FFFFFFFL) {
+        // Same limitation as in X11SurfaceData.c
+        JNU_ThrowOutOfMemoryError(env, "Can't create offscreen surface");
+        return;
+    }
     fp_gdk_threads_enter();
     gtk2_init_painting(env, w, h);
     fp_gdk_threads_leave();