Bug 535123 - [HiDPI][GTK3] Black bands visible in Eclipse UI on x2
display
Fixes black band issues in snippet 365 and tool bars and CTabFolder.
Revert "Revert "Bug 534817 - screenshots do not change""
This reverts commit 742c1cbd39bb33d4c9827db948582faef531b1ba.
This revert fixes SWTBot problem in capturing screenshots
Change-Id: Ibd8dc7ae70befe6db98d89e9d76f7ce68e7ffc8f
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
index 61894e9..8eebf8d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
@@ -1562,6 +1562,11 @@
fromRGB = backgroundRGB;
toRGB = foregroundRGB;
}
+ if (vertical) {
+ width = width * (DPIUtil.getDeviceZoom() / 100);
+ } else {
+ height = height * (DPIUtil.getDeviceZoom() / 100);
+ }
if (fromRGB.equals(toRGB)) {
fillRectangleInPixels(x, y, width, height);
return;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
index 8301156..1c31c6d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
@@ -1390,18 +1390,15 @@
this.type = SWT.BITMAP;
/* Create the pixmap */
- if (GTK.GTK3) {
- surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, width, height);
- } else {
- surface = GDK.gdk_window_create_similar_surface(GDK.gdk_get_default_root_window(), Cairo.CAIRO_CONTENT_COLOR, width, height);
- }
+ surface = GDK.gdk_window_create_similar_surface(GDK.gdk_get_default_root_window(), Cairo.CAIRO_CONTENT_COLOR, width, height);
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- // When we create a blank image we need to set it to 100 in GTK3 as we don't scale here.
- // Cairo will scale for us
+ // When we create a blank image we need to set it to 100 in GTK3 as we draw using 100% scale.
+ // Cairo will take care of scaling for us when image needs to be scaled.
if (!GTK.GTK3) {
currentDeviceZoom = DPIUtil.getDeviceZoom();
} else {
currentDeviceZoom = 100;
+ Cairo.cairo_surface_set_device_scale(surface, 1f, 1f);
}
long /*int*/ cairo = Cairo.cairo_create(surface);
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java
index a611073..0f38b3f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java
@@ -34,9 +34,15 @@
int format = Cairo.cairo_surface_get_content(newSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32;
newSurface = Cairo.cairo_image_surface_create(format, bounds.width, bounds.height);
if (newSurface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ //retain device scale set in the original surface
if (GTK.GTK3) {
- double scaleFactor = DPIUtil.getDeviceZoom() / 100f;
- Cairo.cairo_surface_set_device_scale(newSurface, scaleFactor, scaleFactor);
+ double sx[] = new double[1];
+ double sy[] = new double[1];
+ Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
+ if (sx[0] == 0 || sy[0] == 0){
+ sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
+ }
+ Cairo.cairo_surface_set_device_scale(newSurface, sx[0], sy[0]);
}
long /*int*/ cairo = Cairo.cairo_create(newSurface);
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);