f2e612a
From 87d512619f0b0b05332e4c83f651f29bfa50c5e9 Mon Sep 17 00:00:00 2001
f2e612a
From: Snjezana Peco
f2e612a
Date: Tue, 24 Nov 2015 13:46:51 +0100
f2e612a
Subject: Bug 478962 - [GTK3] Eclipse Mars SR1 consumes 60% CPU while idling
f2e612a
f2e612a
The
f2e612a
https://git.gnome.org/browse/gtk+/commit/?id=fe51ac273c8045279a222c22a52d297d5ede4169
f2e612a
commit changes the state of a node instead of copying the style info.
f2e612a
When getting some properties (color, background color, border, padding),
f2e612a
SWT changes the state of the node 0 (OS.GTK_STATE_FLAG_NORMAL) which
f2e612a
sometimes causes a widget to continously repaint.
f2e612a
For example:
f2e612a
SWT uses the following method to get the background color:
f2e612a
f2e612a
OS.gtk_style_context_get_background_color (context,
f2e612a
OS.GTK_STATE_FLAG_NORMAL, rgba);
f2e612a
f2e612a
This method changes the state of a node to 0 (OS.GTK_STATE_FLAG_NORMAL).
f2e612a
CTabFolder calls the method from inside the paint listener which causes an
f2e612a
infinite painting loop.
f2e612a
f2e612a
This commit fixes the issue by using the widget's current style state
f2e612a
instead of OS.GTK_STATE_FLAG_NORMAL.
f2e612a
f2e612a
Change-Id: I4dd27e3f6c5895a115fd76788ca2b2322aad6c4d
f2e612a
Signed-off-by: Snjezana Peco <snjeza.peco@gmail.com>
f2e612a
---
f2e612a
 bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c |  8 ++++----
f2e612a
 .../gtk/org/eclipse/swt/internal/gtk/OS.java            |  4 ++--
f2e612a
 .../gtk/org/eclipse/swt/widgets/Control.java            | 17 +++++++++++------
f2e612a
 .../gtk/org/eclipse/swt/widgets/DateTime.java           |  8 +++++---
f2e612a
 .../gtk/org/eclipse/swt/widgets/Spinner.java            |  5 +++--
f2e612a
 .../Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java   |  3 ++-
f2e612a
 6 files changed, 27 insertions(+), 18 deletions(-)
f2e612a
f2e612a
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
f2e612a
index c0dff7f..52ade78 100644
f2e612a
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c	
f2e612a
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c	
f2e612a
@@ -18341,18 +18341,18 @@ fail:
f2e612a
 #endif
f2e612a
 
f2e612a
 #ifndef NO__1gtk_1widget_1get_1state_1flags
f2e612a
-JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1widget_1get_1state_1flags)
f2e612a
+JNIEXPORT jint JNICALL OS_NATIVE(_1gtk_1widget_1get_1state_1flags)
f2e612a
 	(JNIEnv *env, jclass that, jintLong arg0)
f2e612a
 {
f2e612a
-	jintLong rc = 0;
f2e612a
+	jint rc = 0;
f2e612a
 	OS_NATIVE_ENTER(env, that, _1gtk_1widget_1get_1state_1flags_FUNC);
f2e612a
 /*
f2e612a
-	rc = (jintLong)gtk_widget_get_state_flags((GtkWidget *)arg0);
f2e612a
+	rc = (jint)gtk_widget_get_state_flags((GtkWidget *)arg0);
f2e612a
 */
f2e612a
 	{
f2e612a
 		OS_LOAD_FUNCTION(fp, gtk_widget_get_state_flags)
f2e612a
 		if (fp) {
f2e612a
-			rc = (jintLong)((jintLong (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0);
f2e612a
+			rc = (jint)((jintLong (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0);
f2e612a
 		}
f2e612a
 	}
f2e612a
 	OS_NATIVE_EXIT(env, that, _1gtk_1widget_1get_1state_1flags_FUNC);
f2e612a
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
f2e612a
index 0ee6dda..a7fb6fe 100644
f2e612a
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java	
f2e612a
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java	
f2e612a
@@ -11855,8 +11855,8 @@ public static final void gtk_style_context_restore(long /*int*/ context) {
f2e612a
 /** @method flags=dynamic
f2e612a
  *  @param self cast=(GtkWidget *)
f2e612a
  *  */
f2e612a
-public static final native long /*int*/ _gtk_widget_get_state_flags(long /*int*/ self);
f2e612a
-public static final long /*int*/ gtk_widget_get_state_flags(long /*int*/ self) {
f2e612a
+public static final native int _gtk_widget_get_state_flags(long /*int*/ self);
f2e612a
+public static final int gtk_widget_get_state_flags(long /*int*/ self) {
f2e612a
 	lock.lock();
f2e612a
 	try {
f2e612a
 		return _gtk_widget_get_state_flags(self);
f2e612a
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
f2e612a
index 7061084..ecf2da0 100644
f2e612a
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java	
f2e612a
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java	
ecd5e2d
@@ -2585,8 +2585,9 @@
ecd5e2d
 		}
ecd5e2d
 	} else {
ecd5e2d
 		long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
ecd5e2d
+		int styleState = OS.gtk_widget_get_state_flags(handle);
ecd5e2d
 		GdkRGBA rgba = new GdkRGBA ();
ecd5e2d
-		OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
ecd5e2d
+		OS.gtk_style_context_get_background_color (context, styleState, rgba);
ecd5e2d
 		if (rgba.alpha == 0) {
ecd5e2d
 			return display.COLOR_WIDGET_BACKGROUND;
ecd5e2d
 		}
f2e612a
@@ -2625,8 +2626,9 @@ GdkColor getContextBackground () {
f2e612a
 GdkColor getContextColor () {
f2e612a
 	long /*int*/ fontHandle = fontHandle ();
f2e612a
 	long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
f2e612a
+	int styleState = OS.gtk_widget_get_state_flags(handle);
f2e612a
 	GdkRGBA rgba = new GdkRGBA ();
f2e612a
-	rgba = display.styleContextGetColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
f2e612a
+	rgba = display.styleContextGetColor (context, styleState, rgba);
f2e612a
 	GdkColor color = new GdkColor ();
f2e612a
 	color.red = (short)(rgba.red * 0xFFFF);
f2e612a
 	color.green = (short)(rgba.green * 0xFFFF);
f2e612a
@@ -2761,7 +2763,8 @@ long /*int*/ getFontDescription () {
f2e612a
 	long /*int*/ fontHandle = fontHandle ();
f2e612a
 	if (OS.GTK3) {
f2e612a
 		long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
f2e612a
-		return OS.gtk_style_context_get_font(context, OS.GTK_STATE_FLAG_NORMAL);
f2e612a
+		int styleState = OS.gtk_widget_get_state_flags(fontHandle);
f2e612a
+		return OS.gtk_style_context_get_font(context, styleState);
f2e612a
 	}
f2e612a
 	OS.gtk_widget_realize (fontHandle);
f2e612a
 	return OS.gtk_style_get_font_desc (OS.gtk_widget_get_style (fontHandle));
f2e612a
@@ -3021,12 +3024,13 @@ Point getThickness (long /*int*/ widget) {
f2e612a
 		int xthickness = 0, ythickness = 0;
f2e612a
 		GtkBorder tmp = new GtkBorder();
f2e612a
 		long /*int*/ context = OS.gtk_widget_get_style_context (widget);
f2e612a
+		int styleState = OS.gtk_widget_get_state_flags(widget);
f2e612a
 		OS.gtk_style_context_save (context);
f2e612a
 		OS.gtk_style_context_add_class (context, OS.GTK_STYLE_CLASS_FRAME);
f2e612a
-		OS.gtk_style_context_get_padding (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
f2e612a
+		OS.gtk_style_context_get_padding (context, styleState, tmp);
f2e612a
 		xthickness += tmp.left;
f2e612a
 		ythickness += tmp.top;
f2e612a
-		OS.gtk_style_context_get_border (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
f2e612a
+		OS.gtk_style_context_get_border (context, styleState, tmp);
f2e612a
 		xthickness += tmp.left;
f2e612a
 		ythickness += tmp.top;
f2e612a
 		OS.gtk_style_context_restore (context);
f2e612a
@@ -5595,7 +5599,8 @@ long /*int*/ windowProc (long /*int*/ handle, long /*int*/ arg0, long /*int*/ us
f2e612a
 				if (OS.GTK3 && !draw && (state & CANVAS) != 0) {
f2e612a
 					GdkRGBA rgba = new GdkRGBA();
f2e612a
 					long /*int*/ context = OS.gtk_widget_get_style_context (handle);
f2e612a
-					OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
f2e612a
+					int styleState = OS.gtk_widget_get_state_flags(handle);
f2e612a
+					OS.gtk_style_context_get_background_color (context, styleState, rgba);
f2e612a
 					draw = rgba.alpha == 0;
f2e612a
 				}
f2e612a
 				if (draw) {
f2e612a
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
f2e612a
index 12bca54..81780bd 100644
f2e612a
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java	
f2e612a
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java	
f2e612a
@@ -296,13 +296,14 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
f2e612a
 		if (OS.GTK3) {
f2e612a
 			GtkBorder tmp = new GtkBorder ();
f2e612a
 			long /*int*/ context = OS.gtk_widget_get_style_context (textEntryHandle);
f2e612a
-			OS.gtk_style_context_get_padding (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
f2e612a
+			int styleState = OS.gtk_widget_get_state_flags(textEntryHandle);
f2e612a
+			OS.gtk_style_context_get_padding (context, styleState, tmp);
f2e612a
 			trim.x -= tmp.left;
f2e612a
 			trim.y -= tmp.top;
f2e612a
 			trim.width += tmp.left + tmp.right;
f2e612a
 			trim.height += tmp.top + tmp.bottom;
f2e612a
 			if ((style & SWT.BORDER) != 0) {
f2e612a
-				OS.gtk_style_context_get_border (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
f2e612a
+				OS.gtk_style_context_get_border (context, styleState, tmp);
f2e612a
 				trim.x -= tmp.left;
f2e612a
 				trim.y -= tmp.top;
f2e612a
 				trim.width += tmp.left + tmp.right;
f2e612a
@@ -1738,7 +1739,8 @@ GtkBorder getGtkBorderPadding () {
f2e612a
 		//In Gtk3, acquire border.
f2e612a
 		GtkBorder gtkBorderPadding = new GtkBorder ();
f2e612a
 		long /*int*/ context = OS.gtk_widget_get_style_context (textEntryHandle);
f2e612a
-		OS.gtk_style_context_get_padding (context, OS.GTK_STATE_FLAG_NORMAL, gtkBorderPadding);
f2e612a
+		int styleState = OS.gtk_widget_get_state_flags(textEntryHandle);
f2e612a
+		OS.gtk_style_context_get_padding (context, styleState, gtkBorderPadding);
f2e612a
 		return gtkBorderPadding;
f2e612a
 	} else {
f2e612a
 		//in GTK2 hard code the padding
f2e612a
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
f2e612a
index 7550122..3bbb886 100644
f2e612a
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java	
f2e612a
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java	
f2e612a
@@ -255,9 +255,10 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
f2e612a
 	if (OS.GTK3) {
f2e612a
 		GtkBorder tmp = new GtkBorder();
f2e612a
 		long /*int*/ context = OS.gtk_widget_get_style_context (handle);
f2e612a
-		OS.gtk_style_context_get_padding (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
f2e612a
+		int styleState = OS.gtk_widget_get_state_flags(handle);
f2e612a
+		OS.gtk_style_context_get_padding (context, styleState, tmp);
f2e612a
 		if ((style & SWT.BORDER) != 0) {
f2e612a
-			OS.gtk_style_context_get_border (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
f2e612a
+			OS.gtk_style_context_get_border (context, styleState, tmp);
f2e612a
 			trim.x -= tmp.left;
f2e612a
 			trim.y -= tmp.top;
f2e612a
 			trim.width += tmp.left + tmp.right;
f2e612a
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
f2e612a
index ee9172e..8d5d0ba 100644
f2e612a
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java	
f2e612a
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java	
f2e612a
@@ -591,7 +591,8 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
f2e612a
 		if (OS.GTK3) {
f2e612a
 			GtkBorder tmp = new GtkBorder();
f2e612a
 			long /*int*/ context = OS.gtk_widget_get_style_context (handle);
f2e612a
-			OS.gtk_style_context_get_padding (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
f2e612a
+			int styleState = OS.gtk_widget_get_state_flags(handle);
f2e612a
+			OS.gtk_style_context_get_padding (context, styleState, tmp);
f2e612a
 			trim.x -= tmp.left;
f2e612a
 			trim.y -= tmp.top;
f2e612a
 			trim.width += tmp.left + tmp.right;
ecd5e2d
@@ -598,7 +602,7 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
ecd5e2d
 			trim.width += tmp.left + tmp.right;
ecd5e2d
 			trim.height += tmp.top + tmp.bottom;
ecd5e2d
 			if ((style & SWT.BORDER) != 0) {
ecd5e2d
-				OS.gtk_style_context_get_border (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
ecd5e2d
+				OS.gtk_style_context_get_border (context, styleState, tmp);
ecd5e2d
 				trim.x -= tmp.left;
ecd5e2d
 				trim.y -= tmp.top;
ecd5e2d
 				trim.width += tmp.left + tmp.right;
f2e612a
-- 
f2e612a
cgit v0.11.2-4-g4a35
f2e612a
f2e612a