Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2018-12-13 20:49:30 +0000
committerEric Williams2019-01-04 18:22:14 +0000
commitd08bf49f03bc05172f2a59b72f8718bab3d3fa9e (patch)
tree424f135ac191e29235a2de38fdd9c4ffc8c80544
parent0f06142510dedcdea84203bb474ddf629609a076 (diff)
downloadeclipse.platform.swt-d08bf49f03bc05172f2a59b72f8718bab3d3fa9e.tar.gz
eclipse.platform.swt-d08bf49f03bc05172f2a59b72f8718bab3d3fa9e.tar.xz
eclipse.platform.swt-d08bf49f03bc05172f2a59b72f8718bab3d3fa9e.zip
Bug 540674: [GTK4] Adapt to new drawing model changes
Implement basic drawing support in SWT-GTK4 as a proof of concept. With patch, Snippet182 draws the Link widget correctly. Change-Id: I256108677f7962207a8eb3d3934979566423650e Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c62
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c36
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h24
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_structs.c9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java29
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/Graphene.java61
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GtkWidgetClass.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java15
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java15
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java36
12 files changed, 292 insertions, 10 deletions
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
index cbaa819dc1..0da9bed84c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2000, 2019 IBM Corporation and others. All rights reserved.
* The contents of this file are made available under the terms
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -8820,6 +8820,18 @@ JNIEXPORT jintLong JNICALL GTK_NATIVE(_1gtk_1settings_1get_1default)
}
#endif
+#ifndef NO__1gtk_1snapshot_1append_1cairo
+JNIEXPORT jintLong JNICALL GTK_NATIVE(_1gtk_1snapshot_1append_1cairo)
+ (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
+{
+ jintLong rc = 0;
+ GTK_NATIVE_ENTER(env, that, _1gtk_1snapshot_1append_1cairo_FUNC);
+ rc = (jintLong)gtk_snapshot_append_cairo((GtkSnapshot *)arg0, (const graphene_rect_t *)arg1);
+ GTK_NATIVE_EXIT(env, that, _1gtk_1snapshot_1append_1cairo_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1gtk_1socket_1get_1id
JNIEXPORT jintLong JNICALL GTK_NATIVE(_1gtk_1socket_1get_1id)
(JNIEnv *env, jclass that, jintLong arg0)
@@ -13024,6 +13036,16 @@ fail:
}
#endif
+#ifndef NO__1gtk_1widget_1snapshot_1child
+JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1widget_1snapshot_1child)
+ (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jintLong arg2)
+{
+ GTK_NATIVE_ENTER(env, that, _1gtk_1widget_1snapshot_1child_FUNC);
+ gtk_widget_snapshot_child((GtkWidget *)arg0, (GtkWidget *)arg1, (GtkSnapshot *)arg2);
+ GTK_NATIVE_EXIT(env, that, _1gtk_1widget_1snapshot_1child_FUNC);
+}
+#endif
+
#if (!defined(NO__1gtk_1widget_1style_1get__I_3B_3II) && !defined(JNI64)) || (!defined(NO__1gtk_1widget_1style_1get__J_3B_3IJ) && defined(JNI64))
#ifndef JNI64
JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1widget_1style_1get__I_3B_3II)(JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jintArray arg2, jintLong arg3)
@@ -13526,6 +13548,44 @@ JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1window_1unmaximize)
}
#endif
+#ifndef Graphene_NATIVE
+#define Graphene_NATIVE(func) Java_org_eclipse_swt_internal_gtk_Graphene_##func
+#endif
+
+#ifndef NO__1graphene_1rect_1alloc
+JNIEXPORT jintLong JNICALL Graphene_NATIVE(_1graphene_1rect_1alloc)
+ (JNIEnv *env, jclass that)
+{
+ jintLong rc = 0;
+ Graphene_NATIVE_ENTER(env, that, _1graphene_1rect_1alloc_FUNC);
+ rc = (jintLong)graphene_rect_alloc();
+ Graphene_NATIVE_EXIT(env, that, _1graphene_1rect_1alloc_FUNC);
+ return rc;
+}
+#endif
+
+#ifndef NO__1graphene_1rect_1free
+JNIEXPORT void JNICALL Graphene_NATIVE(_1graphene_1rect_1free)
+ (JNIEnv *env, jclass that, jintLong arg0)
+{
+ Graphene_NATIVE_ENTER(env, that, _1graphene_1rect_1free_FUNC);
+ graphene_rect_free((graphene_rect_t *)arg0);
+ Graphene_NATIVE_EXIT(env, that, _1graphene_1rect_1free_FUNC);
+}
+#endif
+
+#ifndef NO__1graphene_1rect_1init
+JNIEXPORT jintLong JNICALL Graphene_NATIVE(_1graphene_1rect_1init)
+ (JNIEnv *env, jclass that, jintLong arg0, jfloat arg1, jfloat arg2, jfloat arg3, jfloat arg4)
+{
+ jintLong rc = 0;
+ Graphene_NATIVE_ENTER(env, that, _1graphene_1rect_1init_FUNC);
+ rc = (jintLong)graphene_rect_init((graphene_rect_t *)arg0, arg1, arg2, arg3, arg4);
+ Graphene_NATIVE_EXIT(env, that, _1graphene_1rect_1init_FUNC);
+ return rc;
+}
+#endif
+
#ifndef OS_NATIVE
#define OS_NATIVE(func) Java_org_eclipse_swt_internal_gtk_OS_##func
#endif
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
index 2676362c5c..c0c30a13a9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
@@ -429,6 +429,15 @@
#define NO__1gdk_1surface_1get_1root_1origin
#define NO__1gdk_1surface_1invalidate_1region
+// No GtkSnapshot on GTK3
+#define NO__1gtk_1snapshot_1append_1cairo
+#define NO__1gtk_1widget_1snapshot_1child
+
+// No Graphene library on GTK3
+#define NO__1graphene_1rect_1alloc
+#define NO__1graphene_1rect_1free
+#define NO__1graphene_1rect_1init
+
// Miscellaneous functions not present on GTK3
#define NO__1gdk_1device_1warp__III
#define NO__1gdk_1device_1warp__JII
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
index d46a299e88..1ca440b5b5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
@@ -749,7 +749,6 @@ enum {
static void swt_fixed_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void swt_fixed_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void swt_fixed_finalize (GObject *object);
-static void swt_fixed_realize (GtkWidget *widget);
static void swt_fixed_map (GtkWidget *widget);
static AtkObject *swt_fixed_get_accessible (GtkWidget *widget);
static void swt_fixed_measure (GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum,
@@ -920,6 +919,7 @@ static void swt_fixed_set_property (GObject *object, guint prop_id, const GValue
}
}
+/*
static void swt_fixed_realize (GtkWidget *widget) {
GtkAllocation allocation;
GdkSurface *surface;
@@ -935,7 +935,7 @@ static void swt_fixed_realize (GtkWidget *widget) {
gtk_widget_set_surface(widget, surface);
gdk_surface_set_user_data (surface, widget);
return GTK_WIDGET_CLASS (swt_fixed_parent_class)->realize (widget);
-}
+}*/
static void swt_fixed_map (GtkWidget *widget) {
SwtFixed *fixed = SWT_FIXED (widget);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index 42f35e0a5d..35bad2edca 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2000, 2019 IBM Corporation and others. All rights reserved.
* The contents of this file are made available under the terms
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -793,6 +793,7 @@ char * GTK_nativeFunctionNames[] = {
"_1gtk_1separator_1tool_1item_1new",
"_1gtk_1separator_1tool_1item_1set_1draw",
"_1gtk_1settings_1get_1default",
+ "_1gtk_1snapshot_1append_1cairo",
"_1gtk_1socket_1get_1id",
"_1gtk_1socket_1new",
"_1gtk_1spin_1button_1configure",
@@ -1173,6 +1174,7 @@ char * GTK_nativeFunctionNames[] = {
#else
"_1gtk_1widget_1size_1allocate__JLorg_eclipse_swt_internal_gtk_GtkAllocation_2I",
#endif
+ "_1gtk_1widget_1snapshot_1child",
#ifndef JNI64
"_1gtk_1widget_1style_1get__I_3B_3II",
#else
@@ -1249,6 +1251,38 @@ JNIEXPORT jint JNICALL STATS_NATIVE(GTK_1GetFunctionCallCount)
#endif
#ifdef NATIVE_STATS
+char * Graphene_nativeFunctionNames[] = {
+ "_1graphene_1rect_1alloc",
+ "_1graphene_1rect_1free",
+ "_1graphene_1rect_1init",
+};
+#define NATIVE_FUNCTION_COUNT sizeof(Graphene_nativeFunctionNames) / sizeof(char*)
+int Graphene_nativeFunctionCount = NATIVE_FUNCTION_COUNT;
+int Graphene_nativeFunctionCallCount[NATIVE_FUNCTION_COUNT];
+
+#define STATS_NATIVE(func) Java_org_eclipse_swt_tools_internal_NativeStats_##func
+
+JNIEXPORT jint JNICALL STATS_NATIVE(Graphene_1GetFunctionCount)
+ (JNIEnv *env, jclass that)
+{
+ return Graphene_nativeFunctionCount;
+}
+
+JNIEXPORT jstring JNICALL STATS_NATIVE(Graphene_1GetFunctionName)
+ (JNIEnv *env, jclass that, jint index)
+{
+ return (*env)->NewStringUTF(env, Graphene_nativeFunctionNames[index]);
+}
+
+JNIEXPORT jint JNICALL STATS_NATIVE(Graphene_1GetFunctionCallCount)
+ (JNIEnv *env, jclass that, jint index)
+{
+ return Graphene_nativeFunctionCallCount[index];
+}
+
+#endif
+#ifdef NATIVE_STATS
+
char * OS_nativeFunctionNames[] = {
#ifndef JNI64
"Call__IIII",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index c0f9f3d9b5..47b18611bc 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2000, 2019 IBM Corporation and others. All rights reserved.
* The contents of this file are made available under the terms
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -791,6 +791,7 @@ typedef enum {
_1gtk_1separator_1tool_1item_1new_FUNC,
_1gtk_1separator_1tool_1item_1set_1draw_FUNC,
_1gtk_1settings_1get_1default_FUNC,
+ _1gtk_1snapshot_1append_1cairo_FUNC,
_1gtk_1socket_1get_1id_FUNC,
_1gtk_1socket_1new_FUNC,
_1gtk_1spin_1button_1configure_FUNC,
@@ -1171,6 +1172,7 @@ typedef enum {
#else
_1gtk_1widget_1size_1allocate__JLorg_eclipse_swt_internal_gtk_GtkAllocation_2I_FUNC,
#endif
+ _1gtk_1widget_1snapshot_1child_FUNC,
#ifndef JNI64
_1gtk_1widget_1style_1get__I_3B_3II_FUNC,
#else
@@ -1221,6 +1223,26 @@ typedef enum {
_1gtk_1window_1unmaximize_FUNC,
} GTK_FUNCS;
#ifdef NATIVE_STATS
+extern int Graphene_nativeFunctionCount;
+extern int Graphene_nativeFunctionCallCount[];
+extern char* Graphene_nativeFunctionNames[];
+#define Graphene_NATIVE_ENTER(env, that, func) Graphene_nativeFunctionCallCount[func]++;
+#define Graphene_NATIVE_EXIT(env, that, func)
+#else
+#ifndef Graphene_NATIVE_ENTER
+#define Graphene_NATIVE_ENTER(env, that, func)
+#endif
+#ifndef Graphene_NATIVE_EXIT
+#define Graphene_NATIVE_EXIT(env, that, func)
+#endif
+#endif
+
+typedef enum {
+ _1graphene_1rect_1alloc_FUNC,
+ _1graphene_1rect_1free_FUNC,
+ _1graphene_1rect_1init_FUNC,
+} Graphene_FUNCS;
+#ifdef NATIVE_STATS
extern int OS_nativeFunctionCount;
extern int OS_nativeFunctionCallCount[];
extern char* OS_nativeFunctionNames[];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_structs.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_structs.c
index 98a4547ba1..7ab62ec7d3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_structs.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_structs.c
@@ -1171,7 +1171,7 @@ void setGtkTargetEntryFields(JNIEnv *env, jobject lpObject, GtkTargetEntry *lpSt
typedef struct GtkWidgetClass_FID_CACHE {
int cached;
jclass clazz;
- jfieldID map, size_allocate;
+ jfieldID map, size_allocate, snapshot;
} GtkWidgetClass_FID_CACHE;
GtkWidgetClass_FID_CACHE GtkWidgetClassFc;
@@ -1183,6 +1183,7 @@ void cacheGtkWidgetClassFields(JNIEnv *env, jobject lpObject)
GtkWidgetClassFc.clazz = (*env)->GetObjectClass(env, lpObject);
GtkWidgetClassFc.map = (*env)->GetFieldID(env, GtkWidgetClassFc.clazz, "map", I_J);
GtkWidgetClassFc.size_allocate = (*env)->GetFieldID(env, GtkWidgetClassFc.clazz, "size_allocate", I_J);
+ GtkWidgetClassFc.snapshot = (*env)->GetFieldID(env, GtkWidgetClassFc.clazz, "snapshot", I_J);
GtkWidgetClassFc.cached = 1;
}
@@ -1192,6 +1193,9 @@ GtkWidgetClass *getGtkWidgetClassFields(JNIEnv *env, jobject lpObject, GtkWidget
getGObjectClassFields(env, lpObject, (GObjectClass *)lpStruct);
lpStruct->map = (void(*)())(*env)->GetIntLongField(env, lpObject, GtkWidgetClassFc.map);
lpStruct->size_allocate = (void(*)())(*env)->GetIntLongField(env, lpObject, GtkWidgetClassFc.size_allocate);
+#ifdef GTK4
+ lpStruct->snapshot = (void(*)())(*env)->GetIntLongField(env, lpObject, GtkWidgetClassFc.snapshot);
+#endif
return lpStruct;
}
@@ -1201,6 +1205,9 @@ void setGtkWidgetClassFields(JNIEnv *env, jobject lpObject, GtkWidgetClass *lpSt
setGObjectClassFields(env, lpObject, (GObjectClass *)lpStruct);
(*env)->SetIntLongField(env, lpObject, GtkWidgetClassFc.map, (jintLong)lpStruct->map);
(*env)->SetIntLongField(env, lpObject, GtkWidgetClassFc.size_allocate, (jintLong)lpStruct->size_allocate);
+#ifdef GTK4
+ (*env)->SetIntLongField(env, lpObject, GtkWidgetClassFc.snapshot, (jintLong)lpStruct->snapshot);
+#endif
}
#endif
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
index 06ee6453d3..628c5fd7b0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
@@ -5748,6 +5748,20 @@ public class GTK extends OS {
}
}
/**
+ * @param snapshot cast=(GtkSnapshot *)
+ * @param rect cast=(const graphene_rect_t *)
+ */
+ public static final native long /*int*/ _gtk_snapshot_append_cairo(long /*int*/ snapshot, long /*int*/ rect);
+ /** [GTK4 only, if-def'd in os.h] */
+ public static final long /*int*/ gtk_snapshot_append_cairo(long /*int*/ snapshot, long /*int*/ rect) {
+ lock.lock();
+ try {
+ return _gtk_snapshot_append_cairo(snapshot, rect);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
* @param handle cast=(GtkStatusIcon*)
* @param screen cast=(GdkScreen**)
* @param area cast=(GdkRectangle*)
@@ -9505,4 +9519,19 @@ public class GTK extends OS {
lock.unlock();
}
}
+ /**
+ * @param widget cast=(GtkWidget *)
+ * @param child cast=(GtkWidget *)
+ * @param snapshot cast=(GtkSnapshot *)
+ */
+ public static final native void _gtk_widget_snapshot_child(long /*int*/ widget, long /*int*/ child, long /*int*/ snapshot);
+ /** [GTK4 only, if-def'd in os.h] */
+ public static final void gtk_widget_snapshot_child(long /*int*/ widget, long /*int*/ child, long /*int*/ snapshot) {
+ lock.lock();
+ try {
+ _gtk_widget_snapshot_child(widget,child,snapshot);
+ } finally {
+ lock.unlock();
+ }
+ }
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/Graphene.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/Graphene.java
new file mode 100644
index 0000000000..276b1d66de
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/Graphene.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat Inc. and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.internal.gtk;
+
+/**
+ * This class contains Graphene specific native functions. Please note this library is only relevant
+ * for GTK4 and above.
+ *
+ * In contrast to OS.java, dynamic functions are automatically linked, no need to add os_custom.h entries.
+ */
+public class Graphene extends OS {
+
+ public static final native long /*int*/ _graphene_rect_alloc();
+ /** [GTK4 only, if-def'd in os.h] */
+ public static final long /*int*/ graphene_rect_alloc() {
+ lock.lock();
+ try {
+ return _graphene_rect_alloc();
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
+ * @param rectangle cast=(graphene_rect_t *)
+ */
+ public static final native void _graphene_rect_free(long /*int*/ rectangle);
+ /** [GTK4 only, if-def'd in os.h] */
+ public static final void graphene_rect_free(long /*int*/ rectangle) {
+ lock.lock();
+ try {
+ _graphene_rect_free(rectangle);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
+ * @param rectangle cast=(graphene_rect_t *)
+ */
+ public static final native long /*int*/ _graphene_rect_init(long /*int*/ rectangle, float x, float y, float width, float height);
+ /** [GTK4 only, if-def'd in os.h] */
+ public static final long /*int*/ graphene_rect_init(long /*int*/ rectangle, float x, float y, float width, float height) {
+ lock.lock();
+ try {
+ return _graphene_rect_init(rectangle, x, y, width, height);
+ } finally {
+ lock.unlock();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GtkWidgetClass.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GtkWidgetClass.java
index 51e04b41f0..64b25b6dab 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GtkWidgetClass.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GtkWidgetClass.java
@@ -20,4 +20,6 @@ public class GtkWidgetClass extends GObjectClass {
public long /*int*/ map;
/** @field cast=(void(*)()) */
public long /*int*/ size_allocate;
+ /** @field cast=(void(*)()),exclude=#ifdef GTK4 */
+ public long /*int*/ snapshot;
}
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
index 799ee5e0c7..9f265d8c97 100644
--- 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
@@ -163,11 +163,18 @@ public Control (Composite parent, int style) {
void connectPaint () {
long /*int*/ paintHandle = paintHandle ();
int paintMask = GDK.GDK_EXPOSURE_MASK;
- if (!GTK.GTK4) GTK.gtk_widget_add_events (paintHandle, paintMask);
-
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (EXPOSE_EVENT_INVERSE), false);
+ if (GTK.GTK4 && (hooksPaint() || drawRegion)) {
+ long /*int*/ widgetClass = GTK.GTK_WIDGET_GET_CLASS(paintHandle);
+ GtkWidgetClass widgetClassStruct = new GtkWidgetClass ();
+ OS.memmove(widgetClassStruct, widgetClass);
+ widgetClassStruct.snapshot = display.snapshotDrawProc;
+ OS.memmove(widgetClass, widgetClassStruct);
+ } else {
+ GTK.gtk_widget_add_events (paintHandle, paintMask);
+ OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (EXPOSE_EVENT_INVERSE), false);
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (DRAW), true);
+ OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (DRAW), true);
+ }
}
Font defaultFont () {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 32a101c4ea..1d5dc12a09 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -126,7 +126,9 @@ public class Display extends Device {
int [] max_priority = new int [1], timeout = new int [1];
Callback eventCallback;
long /*int*/ eventProc, windowProc2, windowProc3, windowProc4, windowProc5, windowProc6;
+ long /*int*/ snapshotDrawProc;
Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5, windowCallback6;
+ Callback snapshotDraw;
EventTable eventTable, filterTable;
static String APP_NAME = "SWT"; //$NON-NLS-1$
static String APP_VERSION = ""; //$NON-NLS-1$
@@ -1474,6 +1476,13 @@ static long /*int*/ rendererClassInitProc (long /*int*/ g_class, long /*int*/ cl
return 0;
}
+static long /*int*/ snapshotDrawProc (long /*int*/ handle, long /*int*/ snapshot) {
+ Display display = getCurrent ();
+ Widget widget = display.getWidget (handle);
+ widget.snapshotToDraw(handle, snapshot);
+ return 0;
+}
+
static long /*int*/ rendererGetPreferredWidthProc (long /*int*/ cell, long /*int*/ handle, long /*int*/ minimun_size, long /*int*/ natural_size) {
Display display = getCurrent ();
Widget widget = display.getWidget (handle);
@@ -3577,6 +3586,12 @@ void initializeCallbacks () {
signalIds [Widget.UNREALIZE] = OS.g_signal_lookup (OS.realize, GTK.GTK_TYPE_WIDGET ());
signalIds [Widget.WINDOW_STATE_EVENT] = OS.g_signal_lookup (OS.window_state_event, GTK.GTK_TYPE_WIDGET ());
+ if (GTK.GTK4) {
+ snapshotDraw = new Callback (getClass (), "snapshotDrawProc", 2); //$NON-NLS-1$
+ snapshotDrawProc = snapshotDraw.getAddress ();
+ if (snapshotDrawProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ }
+
windowCallback2 = new Callback (this, "windowProc", 2); //$NON-NLS-1$
windowProc2 = windowCallback2.getAddress ();
if (windowProc2 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
index d424355e8a..1e17cd3a2d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
@@ -1197,6 +1197,19 @@ void postEvent (int eventType, Event event) {
sendEvent (eventType, event, false);
}
+void propagateSnapshot (long /*int*/ widget, long /*int*/ snapshot) {
+ long /*int*/ list = GTK.gtk_container_get_children (widget);
+ long /*int*/ temp = list;
+ while (temp != 0) {
+ long /*int*/ child = OS.g_list_data (temp);
+ if (child != 0) {
+ GTK.gtk_widget_snapshot_child(widget, child, snapshot);
+ }
+ temp = OS.g_list_next (temp);
+ }
+ OS.g_list_free (list);
+}
+
void register () {
if (handle == 0) return;
if ((state & HANDLE) != 0) display.addWidget (handle, this);
@@ -1785,6 +1798,29 @@ long /*int*/ sizeRequestProc (long /*int*/ handle, long /*int*/ arg0, long /*int
return 0;
}
+/**
+ * Converts an incoming snapshot into a gtk_draw() call, complete with
+ * a Cairo context.
+ *
+ * @param handle the widget receiving the snapshot
+ * @param snapshot the actual GtkSnapshot
+ */
+void snapshotToDraw (long /*int*/ handle, long /*int*/ snapshot) {
+ GtkAllocation allocation = new GtkAllocation ();
+ GTK.gtk_widget_get_allocation(handle, allocation);
+ long /*int*/ rect = Graphene.graphene_rect_alloc();
+ Graphene.graphene_rect_init(rect, 0, 0, allocation.width, allocation.height);
+ long /*int*/ cairo = GTK.gtk_snapshot_append_cairo(snapshot, rect);
+ gtk_draw(handle, cairo);
+ Graphene.graphene_rect_free(rect);
+ // Propagates the snapshot down the widget hierarchy so that other widgets
+ // will draw.
+ if (GTK.GTK_IS_CONTAINER(handle)) {
+ propagateSnapshot(handle, snapshot);
+ }
+ return;
+}
+
long /*int*/ gtk_widget_get_window (long /*int*/ widget){
GTK.gtk_widget_realize(widget);
return GTK.gtk_widget_get_window (widget);

Back to the top