Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2019-10-10 17:49:29 +0000
committerEric Williams2019-10-17 12:38:09 +0000
commit3ecf6b0dcc62154585bdeb8c490016cd11afc6c8 (patch)
treed13c0eb8cb5c273ea12d94f9ce6687648c84c074
parentc379608bccf342e5abef5b2591f24ffe25205c71 (diff)
downloadeclipse.platform.swt-3ecf6b0dcc62154585bdeb8c490016cd11afc6c8.tar.gz
eclipse.platform.swt-3ecf6b0dcc62154585bdeb8c490016cd11afc6c8.tar.xz
eclipse.platform.swt-3ecf6b0dcc62154585bdeb8c490016cd11afc6c8.zip
Bug 551982: [GTK] Nothing is rendered when creating new GC on canvas
Use gdk_window_begin_draw_frame() to extract a Cairo context which we can keep for ourselves by calling cairo_reference(). This ensures the context isn't destroyed by gdk_window_end_draw_frame() and can be disposed of in Control.internal_dispose_GC(). Tested on GTK3.24 and 3.20 using the snippet attached and a child Eclipse instance. No AllNonBrowser JUnit tests fail. Change-Id: Ide25a5d742ef69d6fa92906c6f2a861c86d38654 Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java9
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug551982_BlankCanvas.java47
2 files changed, 54 insertions, 2 deletions
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 5208529e7a..00eaa8333f 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
@@ -4287,10 +4287,15 @@ public long internal_new_GC (GCData data) {
long surface;
if (GTK.GTK4) {
surface = GDK.gdk_surface_create_similar_surface(gdkResource, Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
+ gc = Cairo.cairo_create(surface);
} else {
- surface = GDK.gdk_window_create_similar_surface(gdkResource, Cairo.CAIRO_CONTENT_COLOR_ALPHA, data.width, data.height);
+ long cairo_region = GDK.gdk_window_get_visible_region(gdkResource);
+ long drawingContext = GDK.gdk_window_begin_draw_frame(gdkResource, cairo_region);
+ Cairo.cairo_region_destroy(cairo_region);
+ gc = Cairo.cairo_reference(GDK.gdk_drawing_context_get_cairo_context(drawingContext));
+ GDK.gdk_window_end_draw_frame(gdkResource, drawingContext);
}
- gc = Cairo.cairo_create(surface);
+
} else {
gc = GDK.gdk_cairo_create (gdkResource);
}
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug551982_BlankCanvas.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug551982_BlankCanvas.java
new file mode 100644
index 0000000000..a4aaa4807c
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug551982_BlankCanvas.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class Bug551982_BlankCanvas {
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setText("Canvas Example");
+ shell.setLayout(new FillLayout());
+ final Canvas canvas = new Canvas(shell, SWT.NONE);
+ canvas.addPaintListener(e -> {
+ GC gc = new GC(canvas);
+ // Un-commenting this will fix the bug
+// GC gc = e.gc;
+ gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
+ gc.drawFocus(5, 5, 200, 10);
+ gc.drawText("You can draw text directly on a canvas", 60, 60);
+ gc.dispose();
+ });
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+} \ No newline at end of file

Back to the top